Skip to content

Commit

Permalink
Merge pull request librariesio#2827 from librariesio/tiegz/ch18147/rm…
Browse files Browse the repository at this point in the history
…-repository-pages

Remove Repository search routes and views
  • Loading branch information
jsonperl authored May 27, 2021
2 parents ee0367b + 3798667 commit 82926d2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 96 deletions.
6 changes: 1 addition & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@
<% unless on_homepage? && !logged_in? %>
<ul class="nav navbar-nav navbar-left">
<li class=' <%= 'hidden-xs' if on_search_page %>'>
<% if current_host.present? || request.original_fullpath =~ /^\/repos/i %>
<%= render 'repositories/search_form' %>
<% else %>
<%= render 'projects/search_form' %>
<% end %>
<%= render 'projects/search_form' %>
</li>
</ul>
<% end %>
Expand Down
19 changes: 0 additions & 19 deletions app/views/projects/_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
<%= form_tag search_path, method: :get, class: 'navbar-form search_form', enforce_utf8: false do |f| %>
<div class="input-group input-group">

<div class="input-group-btn">
<a type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Search <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
<%= link_to search_path(q: params[:q], sort: params[:sort]) do %>
<%= fa_icon 'check' %>
Packages
<% end %>
</li>
<li>
<%= link_to repo_search_path(q: params[:q], sort: params[:sort]) do %>
<span class='fa-blank'></span>
Repositories
<% end %>
</li>
</ul>
</div>

<%= text_field_tag 'q', "#{@query || '' }", placeholder: 'Search Packages', class: 'form-control search-input', size: 40 %>
<% [:platforms, :licenses, :languages, :keywords, :sort].each do |field| %>
<%= hidden_field_tag field, params[field] if params[field].present? %>
Expand Down
32 changes: 0 additions & 32 deletions app/views/repositories/_search_form.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/repositories/languages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<h4>
<div class="pictogram pictogram-<%= language['key'].downcase %>"></div>
<div class="blurb">
<%= link_to language['key'], github_search_path(language: language['key']) %>
<%= link_to language['key'], search_path(language: language['key']) %>
<small><%= number_to_human language['doc_count'] %> Repos</small>
</div>
</h4>
Expand Down
4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
get "/projects/updated", to: "projects#updated"

scope constraints: { host_type: /(github|gitlab|bitbucket)/i }, defaults: { host_type: "github" } do
get "/:host_type/search", to: "repositories#search"

get "/:host_type/:login/dependencies", to: "repository_users#dependencies"
get "/:host_type/:login/project-contributions", to: "repository_users#project_contributions"
get "/:host_type/:login/repository-contributions", to: "repository_users#repository_contributions"
Expand Down Expand Up @@ -156,7 +154,6 @@
post "/hooks/:host_type", to: "hooks#github"

get "/:host_type/languages", to: "repositories#languages", as: :github_languages
get "/:host_type/search", to: "repositories#search", as: :github_search
get "/:host_type/trending", to: "repositories#hacker_news", as: :trending
get "/:host_type/new", to: "repositories#new", as: :new_repos
get "/:host_type/organisations", to: "repository_organisations#index", as: :repository_organisations
Expand Down Expand Up @@ -188,7 +185,6 @@
get "/:host_type", to: "repositories#index", as: :hosts
end

get "/repos/search", to: "repositories#search", as: :repo_search
get "/repos", to: "repositories#index", as: :repos

get "/search", to: "search#index"
Expand Down
20 changes: 6 additions & 14 deletions spec/requests/api/repositories_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
# frozen_string_literal: true

require "rails_helper"

describe "Api::RepositoriesController" do
let!(:repository) { create(:repository) }

describe "GET /api/github/search", type: :request do
it "renders successfully" do
get '/api/github/search'
expect(response).to have_http_status(:success)
expect(response.content_type).to eq('application/json')
expect(json).to eq []
end
end

describe "GET /api/github/:owner/:name/dependencies", type: :request do
it "renders successfully" do
get "/api/github/#{repository.full_name}/dependencies"
expect(response).to have_http_status(:success)
expect(response.content_type).to eq('application/json')
expect(json.to_json).to be_json_eql repository.as_json({except: [:id, :repository_organisation_id, :repository_user_id], methods: [:github_contributions_count, :github_id]}).merge(dependencies: []).to_json
expect(response.content_type).to eq("application/json")
expect(json.to_json).to be_json_eql repository.as_json({ except: %i[id repository_organisation_id repository_user_id], methods: %i[github_contributions_count github_id] }).merge(dependencies: []).to_json
end
end

describe "GET /api/github/:owner/:name/projects", type: :request do
it "renders successfully" do
get "/api/github/#{repository.full_name}/projects"
expect(response).to have_http_status(:success)
expect(response.content_type).to eq('application/json')
expect(response.content_type).to eq("application/json")
expect(json).to eq []
end
end
Expand All @@ -35,8 +27,8 @@
it "renders successfully" do
get "/api/github/#{repository.full_name}"
expect(response).to have_http_status(:success)
expect(response.content_type).to eq('application/json')
expect(json.to_json).to be_json_eql repository.to_json({except: [:id, :repository_organisation_id, :repository_user_id], methods: [:github_contributions_count, :github_id]})
expect(response.content_type).to eq("application/json")
expect(json.to_json).to be_json_eql repository.to_json({ except: %i[id repository_organisation_id repository_user_id], methods: %i[github_contributions_count github_id] })
end
end
end
27 changes: 6 additions & 21 deletions spec/requests/repositories_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "rails_helper"

describe "RepositoriesController" do
Expand All @@ -8,45 +9,29 @@

describe "GET /github", type: :request do
it "renders successfully when logged out" do
visit hosts_path(host_type: 'github')
expect(page).to have_content 'Repositories'
end
end

describe "GET /github/search", type: :request, elasticsearch: true do
it "renders successfully when logged out" do
Repository.__elasticsearch__.refresh_index!
visit github_search_path
expect(page).to have_content repository.full_name
end
end

describe "GET /github/search.atom", type: :request, elasticsearch: true do
it "renders successfully when logged out" do
Repository.__elasticsearch__.refresh_index!
visit github_search_path(format: :atom)
expect(page).to have_content repository.full_name
visit hosts_path(host_type: "github")
expect(page).to have_content "Repositories"
end
end

describe "GET /github/languages", type: :request do
it "renders successfully when logged out" do
visit github_languages_path
expect(page).to have_content 'Languages'
expect(page).to have_content "Languages"
end
end

describe "GET /github/trending", type: :request do
it "renders successfully when logged out" do
visit trending_path
expect(page).to have_content 'Trending'
expect(page).to have_content "Trending"
end
end

describe "GET /github/new", type: :request do
it "renders successfully when logged out" do
visit new_repos_path
expect(page).to have_content 'New'
expect(page).to have_content "New"
end
end

Expand Down

0 comments on commit 82926d2

Please sign in to comment.