Merge pull request #3719 from consul/remove_redundant_code
Remove redundant code
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
class I18nContent < ApplicationRecord
|
||||
|
||||
scope :by_key, ->(key) { where(key: key) }
|
||||
|
||||
validates :key, uniqueness: true
|
||||
|
||||
translates :value, touch: true
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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) }
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user