diff --git a/app/controllers/languages_controller.rb b/app/controllers/languages_controller.rb
index 0eb79453393..8d1336fefcd 100644
--- a/app/controllers/languages_controller.rb
+++ b/app/controllers/languages_controller.rb
@@ -4,11 +4,6 @@ def index
@languages = Language.default_order
end
- def show
- @language = Language.find_by(short: params[:id])
- @works = @language.works.recent.visible.limit(ArchiveConfig.NUMBER_OF_ITEMS_VISIBLE_IN_DASHBOARD)
- end
-
def new
@language = Language.new
authorize @language
@@ -35,7 +30,7 @@ def update
authorize @language
if @language.update(language_params)
flash[:notice] = t('successfully_updated', default: 'Language was successfully updated.')
- redirect_to @language
+ redirect_to languages_path
else
render action: "new"
end
diff --git a/app/controllers/works_controller.rb b/app/controllers/works_controller.rb
index a18a6be9e51..1f7f70832cf 100755
--- a/app/controllers/works_controller.rb
+++ b/app/controllers/works_controller.rb
@@ -771,7 +771,8 @@ def load_owner
end
end
end
- @owner = @pseud || @user || @collection || @tag
+ @language = Language.find_by(short: params[:language_id]) if params[:language_id].present?
+ @owner = @pseud || @user || @collection || @tag || @language
end
def load_work
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
index d977b0b42f0..dcb9be97318 100644
--- a/app/helpers/search_helper.rb
+++ b/app/helpers/search_helper.rb
@@ -25,6 +25,8 @@ def search_header(collection, search, item_name, parent=nil)
header << ts("by %{byline}", byline: parent.byline)
when User
header << ts("by %{username}", username: parent.login)
+ when Language
+ header << ts("in %{language}", language: parent.name)
end
header << ts("in %{tag_link}", tag_link: link_to_tag_with_text(parent, parent.name)) if parent.is_a?(Tag)
diff --git a/app/models/language.rb b/app/models/language.rb
index f7d7ce974de..2e36a25d13b 100644
--- a/app/models/language.rb
+++ b/app/models/language.rb
@@ -1,4 +1,5 @@
class Language < ApplicationRecord
+ include WorksOwner
validates_presence_of :short
validates :short, uniqueness: true
validates_presence_of :name
diff --git a/app/models/search/work_query.rb b/app/models/search/work_query.rb
index c09eef009f2..75fa7cd7c06 100644
--- a/app/models/search/work_query.rb
+++ b/app/models/search/work_query.rb
@@ -44,6 +44,12 @@ def queries
def add_owner
owner = options[:works_parent]
+
+ if owner.is_a?(Language)
+ options[:language_id] = owner.short
+ return
+ end
+
field = case owner
when Tag
:filter_ids
diff --git a/app/views/languages/show.html.erb b/app/views/languages/show.html.erb
deleted file mode 100644
index 561bd98554e..00000000000
--- a/app/views/languages/show.html.erb
+++ /dev/null
@@ -1,21 +0,0 @@
-
<%= @language.name %>
-
-
-<% if logged_in_as_admin? %>
-
- <%= link_to ts('Edit Language'), edit_language_path(@language) %>
-
-<% end %>
-
-
-
-<%= link_to t('.work_count', :default => "%{count} works", :count => @language.work_count), language_works_path(@language) %> in <%= @language.fandom_count %> fandoms
-
-<% unless @works.blank? %>
- Most recent works:
-
- <% for work in @works %>
- <%= render :partial => 'works/work_blurb', :locals => {:work => work} %>
- <% end %>
-
-<% end %>
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index e0c027fe8f0..59c40e47760 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -509,10 +509,11 @@
#### I18N ####
# should stay below the main works mapping
- resources :languages do
+ resources :languages, except: [:show] do
resources :works
resources :admin_posts
end
+ get "/languages/:id", to: redirect("/languages/%{id}/works", status: 302)
resources :locales, except: :destroy
#### API ####
diff --git a/features/other_a/languages.feature b/features/other_a/languages.feature
index 79cc74b47d5..37a7f1537af 100644
--- a/features/other_a/languages.feature
+++ b/features/other_a/languages.feature
@@ -37,9 +37,10 @@ Feature: Languages
# Browse works in a language
When I am on the languages page
+ And all indexing jobs have been run
Then I should see "Deutsch"
When I follow "Deutsch"
- Then I should see "1 works in 1 fandoms"
+ Then I should see "1 Work in Deutsch"
And I should see "Die Rache der Sith"
And I should not see "Revenge of the Sith"
diff --git a/features/step_definitions/work_steps.rb b/features/step_definitions/work_steps.rb
index 0560591ef9f..2937753f6ae 100644
--- a/features/step_definitions/work_steps.rb
+++ b/features/step_definitions/work_steps.rb
@@ -564,6 +564,14 @@
step "the periodic tag count task is run"
end
+When "I browse works in language {string}" do |language_name|
+ step %{all indexing jobs have been run}
+ step "the periodic tag count task is run"
+
+ language = Language.find_by(name: language_name)
+ visit language_works_path(language)
+end
+
When /^I delete the work "([^"]*)"$/ do |work|
work = Work.find_by(title: CGI.escapeHTML(work))
visit edit_work_path(work)
diff --git a/features/works/work_browse.feature b/features/works/work_browse.feature
index 4540fa91cf8..85bc9c82b17 100644
--- a/features/works/work_browse.feature
+++ b/features/works/work_browse.feature
@@ -147,3 +147,27 @@ chapter when the chapters are reordered.
When I follow the comments link for the work "Awesome Work"
Then I should be on the work "Awesome Work"
And I should see "Bravo!"
+
+Scenario: Can also browse work indexed by language
+ Given basic languages
+ And Persian language
+ And basic tags
+ And I am logged in
+ And I post the work "Whatever 1" with fandom "Aggressive Retsuko"
+ And I post the work "Whatever 2" with fandom "Aggressive Retsuko"
+ When I go to the new work page
+ And I select "Not Rated" from "Rating"
+ And I check "No Archive Warnings Apply"
+ And I fill in "Fandoms" with "Weiß Kreuz"
+ And I fill in "Work Title" with "Überraschende Überraschung"
+ And I fill in "content" with "Dies ist eine Fanfic in Deutsch."
+ And I select "Deutsch" from "Choose a language"
+ When I press "Post"
+ Then I should see "Work was successfully posted."
+ And I should see "Deutsch" within "dd.language"
+ When I browse works in language "English"
+ Then I should see "2 Works in English"
+ When I browse works in language "Deutsch"
+ Then I should see "1 Work in Deutsch"
+ When I browse works in language "Persian"
+ Then I should see "0 Works in Persian"
diff --git a/spec/controllers/languages_controller_spec.rb b/spec/controllers/languages_controller_spec.rb
index 17d8f2383c9..11ce30ce6c3 100644
--- a/spec/controllers/languages_controller_spec.rb
+++ b/spec/controllers/languages_controller_spec.rb
@@ -25,26 +25,6 @@
end
end
- describe "GET show" do
- context "when not logged in" do
- it "renders the show template" do
- get :show, params: { id: "en" }
- expect(response).to render_template("show")
- end
- end
-
- Admin::VALID_ROLES.each do |role|
- context "when logged in as an admin with #{role} role" do
- let(:admin) { create(:admin, roles: [role]) }
-
- it "renders the show template" do
- get :show, params: { id: "en" }
- expect(response).to render_template("show")
- end
- end
- end
- end
-
describe "GET new" do
context "when not logged in" do
it "redirects with error" do
@@ -227,7 +207,7 @@
end
it "redirects and returns success message" do
- it_redirects_to_with_notice(finnish, "Language was successfully updated.")
+ it_redirects_to_with_notice(languages_path, "Language was successfully updated.")
end
end
end