diff --git a/app/models/i18n_content.rb b/app/models/i18n_content.rb index 79a04b20a..163f9329a 100644 --- a/app/models/i18n_content.rb +++ b/app/models/i18n_content.rb @@ -1,7 +1,4 @@ class I18nContent < ApplicationRecord - - scope :by_key, ->(key) { where(key: key) } - validates :key, uniqueness: true translates :value, touch: true diff --git a/config/initializers/i18n_translation.rb b/config/initializers/i18n_translation.rb index fb23270cd..aa500468c 100644 --- a/config/initializers/i18n_translation.rb +++ b/config/initializers/i18n_translation.rb @@ -9,7 +9,7 @@ module ActionView def t(key, options = {}) current_locale = options[:locale].presence || I18n.locale - i18_content = I18nContent.by_key(key).first + i18_content = I18nContent.find_by_key(key) translation = I18nContentTranslation.where(i18n_content_id: i18_content&.id, locale: current_locale).first&.value translation.presence || translate(key, options) diff --git a/spec/features/admin/poll/questions/answers/documents/documents_spec.rb b/spec/features/admin/poll/questions/answers/documents/documents_spec.rb index 17340d98d..c8c59cd79 100644 --- a/spec/features/admin/poll/questions/answers/documents/documents_spec.rb +++ b/spec/features/admin/poll/questions/answers/documents/documents_spec.rb @@ -9,7 +9,7 @@ describe "Documents" do context "Index" do scenario "Answer with no documents" do - answer = create(:poll_question_answer, question: create(:poll_question)) + answer = create(:poll_question_answer) document = create(:document) visit admin_answer_documents_path(answer) @@ -18,7 +18,7 @@ describe "Documents" do end scenario "Answer with documents" do - answer = create(:poll_question_answer, question: create(:poll_question)) + answer = create(:poll_question_answer) document = create(:document, documentable: answer) visit admin_answer_documents_path(answer) @@ -28,7 +28,7 @@ describe "Documents" do end scenario "Remove document from answer", :js do - answer = create(:poll_question_answer, question: create(:poll_question)) + answer = create(:poll_question_answer) document = create(:document, documentable: answer) visit admin_answer_documents_path(answer) diff --git a/spec/features/admin/poll/questions/answers/images/images_spec.rb b/spec/features/admin/poll/questions/answers/images/images_spec.rb index 474b63a5c..db8b7a26d 100644 --- a/spec/features/admin/poll/questions/answers/images/images_spec.rb +++ b/spec/features/admin/poll/questions/answers/images/images_spec.rb @@ -9,8 +9,7 @@ describe "Images" do context "Index" do scenario "Answer with no images" do - answer = create(:poll_question_answer, - question: create(:poll_question)) + answer = create(:poll_question_answer) visit admin_answer_images_path(answer) @@ -18,8 +17,7 @@ describe "Images" do end scenario "Answer with images" do - answer = create(:poll_question_answer, - question: create(:poll_question)) + answer = create(:poll_question_answer) image = create(:image, imageable: answer) visit admin_answer_images_path(answer) @@ -30,8 +28,7 @@ describe "Images" do end scenario "Add image to answer", :js do - answer = create(:poll_question_answer, - question: create(:poll_question)) + answer = create(:poll_question_answer) image = create(:image) visit admin_answer_images_path(answer) @@ -47,8 +44,7 @@ describe "Images" do end scenario "Remove image from answer", :js do - answer = create(:poll_question_answer, - question: create(:poll_question)) + answer = create(:poll_question_answer) image = create(:image, imageable: answer) visit admin_answer_images_path(answer) diff --git a/spec/features/budget_polls/officing_spec.rb b/spec/features/budget_polls/officing_spec.rb index d9ae81cac..5dab07e05 100644 --- a/spec/features/budget_polls/officing_spec.rb +++ b/spec/features/budget_polls/officing_spec.rb @@ -3,9 +3,8 @@ require "rails_helper" describe "Budget Poll Officing" do scenario "Show sidebar menus if officer has shifts assigned" do - poll = create(:poll) booth = create(:poll_booth) - booth_assignment = create(:poll_booth_assignment, poll: poll, booth: booth) + booth_assignment = create(:poll_booth_assignment, booth: booth) user = create(:user) officer = create(:poll_officer, user: user) diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb index 707dbf0da..11e5b3eaa 100644 --- a/spec/features/budgets/ballots_spec.rb +++ b/spec/features/budgets/ballots_spec.rb @@ -434,8 +434,7 @@ describe "Ballots" do scenario "Display links to vote on groups with no investments voted yet" do group = create(:budget_group, budget: budget) - heading = create(:budget_heading, name: "District 1", group: group, price: 100) - + heading = create(:budget_heading, group: group) ballot = create(:budget_ballot, user: user, budget: budget) login_as(user) diff --git a/spec/features/polls/polls_spec.rb b/spec/features/polls/polls_spec.rb index 02ba30eb5..7d392bbab 100644 --- a/spec/features/polls/polls_spec.rb +++ b/spec/features/polls/polls_spec.rb @@ -483,6 +483,17 @@ describe "Polls" do expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.") end + scenario "Do not show poll results or stats to admins if disabled" do + poll = create(:poll, :expired, results_enabled: false, stats_enabled: false) + admin = create(:administrator).user + + login_as admin + visit poll_path(poll) + + expect(page).not_to have_content("Poll results") + expect(page).not_to have_content("Participation statistics") + end + scenario "Don't show poll results and stats if is not expired" do poll = create(:poll, :current, results_enabled: true, stats_enabled: true) user = create(:user) @@ -500,30 +511,6 @@ describe "Polls" do expect(page).to have_content("You do not have permission to carry out the action 'stats' on poll.") end - scenario "Do not show poll results or stats if are disabled" do - poll = create(:poll, :expired, results_enabled: false, stats_enabled: false) - question1 = create(:poll_question, poll: poll) - create(:poll_question_answer, question: question1, title: "Han Solo") - create(:poll_question_answer, question: question1, title: "Chewbacca") - question2 = create(:poll_question, poll: poll) - create(:poll_question_answer, question: question2, title: "Leia") - create(:poll_question_answer, question: question2, title: "Luke") - user = create(:user) - admin = create(:administrator).user - - login_as user - visit poll_path(poll) - - expect(page).not_to have_content("Poll results") - expect(page).not_to have_content("Participation statistics") - - login_as admin - visit poll_path(poll) - - expect(page).not_to have_content("Poll results") - expect(page).not_to have_content("Participation statistics") - end - scenario "Generates navigation links for polls without a slug" do poll = create(:poll, :expired, results_enabled: true, stats_enabled: true) poll.update_column(:slug, nil) diff --git a/spec/features/proposal_notifications_spec.rb b/spec/features/proposal_notifications_spec.rb index 55230ba25..cbf542f58 100644 --- a/spec/features/proposal_notifications_spec.rb +++ b/spec/features/proposal_notifications_spec.rb @@ -29,8 +29,7 @@ describe "Proposal Notifications" do end scenario "Send a notification (Active voter)" do - author = create(:user) - proposal = create(:proposal, author: author) + proposal = create(:proposal) voter = create(:user, :level_two) create(:vote, voter: voter, votable: proposal) @@ -41,8 +40,7 @@ describe "Proposal Notifications" do end scenario "Send a notification (Follower)" do - author = create(:user) - proposal = create(:proposal, author: author) + proposal = create(:proposal) user_follower = create(:user) create(:follow, :followed_proposal, user: user_follower, followable: proposal) @@ -52,8 +50,7 @@ describe "Proposal Notifications" do end scenario "Send a notification (Follower and Voter)" do - author = create(:user) - proposal = create(:proposal, author: author) + proposal = create(:proposal) user_voter_follower = create(:user) create(:follow, :followed_proposal, user: user_voter_follower, followable: proposal) @@ -68,8 +65,7 @@ describe "Proposal Notifications" do end scenario "Send a notification (Blocked voter)" do - author = create(:user) - proposal = create(:proposal, author: author) + proposal = create(:proposal) voter = create(:user, :level_two) create(:vote, voter: voter, votable: proposal) @@ -81,8 +77,7 @@ describe "Proposal Notifications" do end scenario "Send a notification (Erased voter)" do - author = create(:user) - proposal = create(:proposal, author: author) + proposal = create(:proposal) voter = create(:user, :level_two) create(:vote, voter: voter, votable: proposal) diff --git a/spec/lib/reply_email_spec.rb b/spec/lib/reply_email_spec.rb index 87819e3d1..68054e08f 100644 --- a/spec/lib/reply_email_spec.rb +++ b/spec/lib/reply_email_spec.rb @@ -1,9 +1,7 @@ require "rails_helper" describe ReplyEmail do - - let(:author) { create(:user) } - let(:debate) { create(:debate, author: author) } + let(:debate) { create(:debate) } let(:commenter) { create(:user, email: "email@commenter.org") } let(:comment) { create(:comment, commentable: debate, user: commenter) } let(:replier) { create(:user) } diff --git a/spec/models/i18n_content_spec.rb b/spec/models/i18n_content_spec.rb index 974218605..aade19cfc 100644 --- a/spec/models/i18n_content_spec.rb +++ b/spec/models/i18n_content_spec.rb @@ -14,21 +14,6 @@ RSpec.describe I18nContent, type: :model do expect(i18n_content.errors.size).to eq(1) end - context "Scopes" do - it "return one record when #by_key is used" do - content = create(:i18n_content) - key = "debates.form.debate_title" - debate_title = create(:i18n_content, key: key) - - expect(I18nContent.all.size).to eq(2) - - query = I18nContent.by_key(key) - - expect(query.size).to eq(1) - expect(query).to eq([debate_title]) - end - end - context "Globalize" do it "translates key into multiple languages" do key = "devise_views.mailer.confirmation_instructions.welcome" diff --git a/spec/models/poll/shift_spec.rb b/spec/models/poll/shift_spec.rb index 5baaede91..539a5f988 100644 --- a/spec/models/poll/shift_spec.rb +++ b/spec/models/poll/shift_spec.rb @@ -57,10 +57,8 @@ describe Poll::Shift do describe "officer_assignments" do it "creates and destroy corresponding officer_assignments" do - poll2 = create(:poll) - - booth_assignment1 = create(:poll_booth_assignment, poll: poll, booth: booth) - booth_assignment2 = create(:poll_booth_assignment, poll: poll2, booth: booth) + booth_assignment1 = create(:poll_booth_assignment, booth: booth) + booth_assignment2 = create(:poll_booth_assignment, booth: booth) expect { create(:poll_shift, booth: booth, officer: officer, date: Date.current) }.to change { Poll::OfficerAssignment.all.count }.by(2)