Skip to content

Commit

Permalink
AO3-5702 Require language when posting a new work (#3614)
Browse files Browse the repository at this point in the history
* AO3-5702 Require language when posting a new work

Previously, the form to post a new work defaulted to selecting English[1] as the work language.

This has lead to numerous works in different languages being listed as "English".

In order to minimise the number of mislabeled works, the language is now required, and there is no default selection.

[1] Or rather the default language, which for the Archive is English.

* AO3-5702 Add the asterisk of requirement
  • Loading branch information
CristinaRO authored and sarken committed Nov 11, 2019
1 parent e169e3e commit dde601d
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 14 deletions.
6 changes: 6 additions & 0 deletions app/models/work.rb
Expand Up @@ -104,6 +104,12 @@ def title
maximum: ArchiveConfig.NOTES_MAX,
too_long: ts("must be less than %{max} characters long.", max: ArchiveConfig.NOTES_MAX)

validate :language_present_and_supported

def language_present_and_supported
errors.add(:base, ts("Language cannot be blank.")) if self.language.blank?
end

# Makes sure the title has no leading spaces
validate :clean_and_validate_title

Expand Down
9 changes: 5 additions & 4 deletions app/views/works/_work_form_associations_language.html.erb
@@ -1,11 +1,12 @@
<% # expects local variable f %>
<dt class="language">
<%= f.label :language_id, ts('Choose a language') %>
<dt class="language required">
<%= f.label :language_id, ts("Choose a language") + "*" %>
<%= link_to_help "languages-help" %>
</dt>
<dd class="language">
<dd class="language required">
<select id="work_language_id" name="work[language_id]">
<option value=""><%= ts("Please select a language") %></option>
<%= options_from_collection_for_select(sorted_languages, :id, :name,
@work.language_id || Language.default.id) %>
@work.language_id) %>
</select>
</dd>
1 change: 1 addition & 0 deletions factories/works.rb
Expand Up @@ -6,6 +6,7 @@
fandom_string { "Testing" }
rating_string { "Not Rated" }
archive_warning_string { "No Archive Warnings Apply" }
language_id { Language.default.id }
chapter_info = { content: "This is some chapter content for my work." }
chapter_attributes { chapter_info }

Expand Down
1 change: 1 addition & 0 deletions features/collections/collection_navigation.feature
Expand Up @@ -21,6 +21,7 @@ Feature: Basic collection navigation
And I fill in "Fandoms" with "New Fandom"
And I fill in "Additional Tags" with "Free"
And I fill in "Work Title" with "Work for my collection"
And I select "English" from "Choose a language"
And I fill in "content" with "First because I'm the mod"
And I fill in "Post to Collections / Challenges" with "my_collection"
And I press "Preview"
Expand Down
1 change: 1 addition & 0 deletions features/gift_exchanges/challenge_yuletide.feature
Expand Up @@ -432,6 +432,7 @@ Feature: Collection
And I fill in "Fandoms" with "Stargate Atlantis"
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "content" with "This is an exciting story about Atlantis"
When I press "Preview"
Then I should see "Preview"
Expand Down
1 change: 1 addition & 0 deletions features/other_a/help.feature
Expand Up @@ -25,6 +25,7 @@ Scenario: view the help popup for chapter title
And I check "No Archive Warnings Apply"
And I fill in "Fandoms" with "New Fandom"
And I fill in "Work Title" with "New Epic Work"
And I select "English" from "Choose a language"
And I fill in "content" with "Well, maybe not so epic."
And I press "Post"
And I follow "Add Chapter"
Expand Down
1 change: 1 addition & 0 deletions features/other_b/sanitizer.feature
Expand Up @@ -33,6 +33,7 @@ Feature: Sanitizing HTML
Then I should see "Post New Work"
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Supernatural"
And I fill in "Work Title" with "All Hell Breaks Loose"
And I fill in "content" with 'BODY{-moz-binding:url("http://ha.ckers.org/xssmoz.xml#xss")}'
Expand Down
Expand Up @@ -30,6 +30,7 @@ Feature: Prompt Meme Challenge
Then I should see "New claim made"
And I follow "Fulfill"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "GhostSoup"
And I should see "promptcollection" in the "work_collection_names" input
And the "Untitled Prompt in The Kissing Game (Anonymous)" checkbox should be checked
Expand Down Expand Up @@ -420,6 +421,7 @@ Feature: Prompt Meme Challenge
And I fill in "Work Title*" with "Fulfilled Story-thing"
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "content" with "This is an exciting story about Atlantis, but in a different universe this time"
When I press "Preview"
And I press "Post"
Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/challege_gift_exchange_steps.rb
Expand Up @@ -314,6 +314,7 @@
step %{I fill in "Work Title" with "Fulfilled Story"}
step %{I select "Not Rated" from "Rating"}
step %{I check "No Archive Warnings Apply"}
step %{I select "English" from "Choose a language"}
step %{I fill in "Fandom" with "Final Fantasy X"}
step %{I fill in "content" with "This is a really cool story about Final Fantasy X"}
end
Expand Down
2 changes: 2 additions & 0 deletions features/step_definitions/challenge_promptmeme_steps.rb
Expand Up @@ -363,6 +363,7 @@
step %{I fill in "Work Title" with "#{title}"}
step %{I select "Not Rated" from "Rating"}
step %{I check "No Archive Warnings Apply"}
step %{I select "English" from "Choose a language"}
step %{I fill in "Fandom" with "Stargate Atlantis"}
step %{I fill in "content" with "This is an exciting story about Atlantis"}
end
Expand All @@ -386,6 +387,7 @@
step %{I fill in "Work Title" with "Second Story"}
step %{I select "Not Rated" from "Rating"}
step %{I check "No Archive Warnings Apply"}
step %{I select "English" from "Choose a language"}
step %{I fill in "Fandom" with "Stargate Atlantis"}
step %{I fill in "content" with "This is an exciting story about Atlantis"}
step %{I press "Preview"}
Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/challenge_yuletide_steps.rb
Expand Up @@ -8,6 +8,7 @@
step %{I fill in "Fandoms" with "#{fandom}"}
step %{I select "Not Rated" from "Rating"}
step %{I check "No Archive Warnings Apply"}
step %{I select "English" from "Choose a language"}
step %{I fill in "content" with "This is an exciting story about #{fandom}"}
step %{I press "Preview"}
end
Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/work_related_steps.rb
Expand Up @@ -64,6 +64,7 @@
step %{I go to the new work page}
step %{I select "Not Rated" from "Rating"}
step %{I check "No Archive Warnings Apply"}
step %{I select "English" from "Choose a language"}
step %{I fill in "Fandoms" with "Stargate"}
step %{I fill in "Work Title" with "Followup"}
step %{I fill in "content" with "That could be an amusing crossover."}
Expand Down
1 change: 1 addition & 0 deletions features/step_definitions/work_steps.rb
Expand Up @@ -13,6 +13,7 @@
step %{I fill in basic work tags}
check(DEFAULT_WARNING)
fill_in("Work Title", with: title)
select("English", from: "work_language_id")
fill_in("content", with: DEFAULT_CONTENT)
end
# Here we set up a draft and can then post it as a draft, preview and post, post,
Expand Down
1 change: 1 addition & 0 deletions features/tags_and_wrangling/tag_cloud.feature
Expand Up @@ -34,6 +34,7 @@ Scenario: tag cloud should only contain top-level canonical freeforms in "No Fan
And I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Firefly"
And I fill in "Work Title" with "Silliness"
And I fill in "Additional Tags" with "100 words, five things, objects in space, Sentient Serenity, Episode Tag, Non-canonical NoFandom, Non-canonical Fandomish, Non-canonical unwrangled, Canonical Fandomish, Canonical unwrangled"
Expand Down
1 change: 1 addition & 0 deletions features/tags_and_wrangling/tag_wrangling.feature
Expand Up @@ -49,6 +49,7 @@ Feature: Tag wrangling
When I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Stargate SG-1, Star Wars"
And I fill in "Work Title" with "Revenge of the Sith 2"
And I fill in "Characters" with "Daniel Jackson, Jack O'Neil"
Expand Down
Expand Up @@ -75,6 +75,7 @@ Scenario: character wrangling - syns, mergers, characters, autocompletes
And I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Doctor Who"
And I fill in "Work Title" with "Silliness"
And I fill in "Characters" with "1st Doctor, One"
Expand Down
1 change: 1 addition & 0 deletions features/tags_and_wrangling/tag_wrangling_fandoms.feature
Expand Up @@ -46,6 +46,7 @@ Scenario: fandoms wrangling - syns, mergers, autocompletes, metatags
When I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "SG1, the whole Stargate franchise, Stargates SG-1"
And I fill in "Work Title" with "Silliness"
And I fill in "content" with "And then everyone was kidnapped by an alien bus."
Expand Down
Expand Up @@ -44,6 +44,7 @@ Scenario: freeforms wrangling - syns, mergers, autocompletes, metatags
When I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Torchwood"
And I fill in "Work Title" with "Silliness"
And I fill in "Additional Tags" with "Pirate AU, Arrr-verse"
Expand Down
Expand Up @@ -67,6 +67,7 @@ Scenario: relationship wrangling - syns, mergers, characters, autocompletes
And I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Torchwood"
And I fill in "Work Title" with "Silliness"
And I fill in "Relationships" with "Janto, Jack/Ianto"
Expand Down Expand Up @@ -225,6 +226,7 @@ Scenario: AO3-2147 Creating a new merger to a non-can tag while adding character
# create a relationship from posting a work as a regular user, just in case
Given I am logged in as "writer" with password "password"
And I follow "New Work"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Up with Testing"
And I fill in "Work Title" with "whatever"
And I fill in "Relationships" with "Testypants/Testyskirt"
Expand Down
2 changes: 2 additions & 0 deletions features/works/chapter_edit.feature
Expand Up @@ -19,6 +19,7 @@ Feature: Edit chapters
Then I should see "Post New Work"
When I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "New Fandom"
And I fill in "Work Title" with "New Epic Work"
And I fill in "content" with "Well, maybe not so epic."
Expand Down Expand Up @@ -204,6 +205,7 @@ Feature: Edit chapters
Then I should see "Post New Work"
And I select "General Audiences" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "If You Give an X a Y"
And I fill in "Work Title" with "If You Give Users a Draft Feature"
And I fill in "content" with "They will expect it to work."
Expand Down
3 changes: 3 additions & 0 deletions features/works/work_create.feature
Expand Up @@ -15,6 +15,7 @@ Feature: Create Works
Then I should see "Post New Work"
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Supernatural"
And I fill in "Work Title" with "All Hell Breaks Loose 🤬💩"
And I fill in "content" with "Bad things happen, etc. 🤬💩"
Expand Down Expand Up @@ -68,6 +69,7 @@ Feature: Create Works
When I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I check "F/M"
And I fill in "Fandoms" with "Supernatural"
And I fill in "Work Title" with "All Something Breaks Loose"
Expand Down Expand Up @@ -295,6 +297,7 @@ Feature: Create Works
Given basic tags
And I am logged in
When I go to the new work page
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Dallas"
And I fill in "Work Title" with "I Shot J.R.: Kristin's Story"
And I fill in "content" with "It wasn't my fault, you know."
Expand Down
1 change: 1 addition & 0 deletions features/works/work_delete.feature
Expand Up @@ -53,6 +53,7 @@ Feature: Delete Works
And all emails have been delivered
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I check "F/M"
And I fill in "Fandoms" with "Supernatural"
And I fill in "Work Title" with "All Something Breaks Loose"
Expand Down
1 change: 1 addition & 0 deletions features/works/work_drafts.feature
Expand Up @@ -15,6 +15,7 @@ Feature: Work Drafts
Then I should see "Post New Work"
And I select "General Audiences" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "MASH (TV)"
And I fill in "Work Title" with "Draft Dodging"
And I fill in "content" with "Klinger lay under his porch."
Expand Down
11 changes: 6 additions & 5 deletions features/works/work_languages.feature
Expand Up @@ -4,9 +4,9 @@ Feature: Create Works
In order to have an archive full of works
As an author
I want to create new works

Scenario: Creating a new work with international characters

Given basic tags
And basic languages
And I am logged in as "germanfan" with password "password"
Expand All @@ -31,14 +31,15 @@ Feature: Create Works
Then I should see "Dies ist eine Fanfic in Deutsch."
When I log out
Then I should see "Successfully logged out"
# another example in a different language

# another example with a different character set (language not in fixtures)

Given I am logged in as "finnishfan" with password "password"
When I go to the new work page
Then I should see "Post New Work"
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "A fandom"
And I fill in "Work Title" with "Ennen päivänlaskua ei voi"
And I fill in "content" with "A story that is long enough to count"
Expand Down
1 change: 1 addition & 0 deletions features/works/work_lock.feature
Expand Up @@ -12,6 +12,7 @@ Scenario: Posting locked work
And I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Supernatural"
And I fill in "Characters" with "Sammy"
And I fill in "Work Title" with "Awesomeness"
Expand Down
1 change: 1 addition & 0 deletions features/works/work_related.feature
Expand Up @@ -302,6 +302,7 @@ Scenario: External work language
And I go to the new work page
And I select "Not Rated" from "Rating"
And I check "No Archive Warnings Apply"
And I select "English" from "Choose a language"
And I fill in "Fandoms" with "Stargate"
And I fill in "Work Title" with "Followup 4"
And I fill in "content" with "That could be an amusing crossover."
Expand Down
2 changes: 1 addition & 1 deletion spec/models/search/bookmark_search_form_spec.rb
Expand Up @@ -93,7 +93,7 @@
describe "searching" do
let(:language) { create(:language, short: "ptBR") }

let(:work1) { create(:posted_work, language_id: Language.default.id) }
let(:work1) { create(:posted_work) }
let(:work2) { create(:posted_work, language_id: language.id) }

let!(:bookmark1) { create(:bookmark, bookmarkable: work1) }
Expand Down
3 changes: 1 addition & 2 deletions spec/models/search/work_search_form_spec.rb
Expand Up @@ -126,8 +126,7 @@
character_string: "Bilbo Baggins",
posted: true,
expected_number_of_chapters: 3,
complete: false,
language_id: Language.default.id)
complete: false)
end

let!(:second_work) do
Expand Down
30 changes: 28 additions & 2 deletions spec/models/work_spec.rb
Expand Up @@ -76,14 +76,41 @@
end
end


context "invalid endnotes" do
let(:too_long) { ArchiveConfig.NOTES_MAX + 1 }
it "cannot be longer than ArchiveConfig.NOTES_MAX" do
expect(build(:work, title: Faker::Lorem.characters(too_long))).to be_invalid
end
end

context "invalid language" do
let(:deleted_language_id) do
briefly_lived_language = create(:language)
deleted_language_id = briefly_lived_language.id
briefly_lived_language.destroy
deleted_language_id
end

it "is valid with a supported language" do
work = build(:work, language_id: Language.default.id)
expect(work).to be_valid
end

it "is not valid with a language we don't support" do
work = build(:work, language_id: deleted_language_id)

expect(work).not_to be_valid
expect(work.errors.messages[:base]).to include("Language cannot be blank.")
end

it "is not valid without a language" do
work = build(:work, language_id: "")

expect(work).not_to be_valid
expect(work.errors.messages[:base]).to include("Language cannot be blank.")
end
end

context "validate authors" do
let(:invalid_work) { build(:no_authors) }

Expand Down Expand Up @@ -385,7 +412,6 @@
@work.recipients = @recipient2.pseuds.first.name + "," + @recipient2.pseuds.first.name
expect(@work.new_recipients).to eq(@recipient2.pseuds.first.name)
end

end

describe "#find_by_url" do
Expand Down

0 comments on commit dde601d

Please sign in to comment.