Move relationable expectations to controller tests
Having expectations related to database operations in system tests after the process running the browser has started might result in exceptions while running our test suite.
This commit is contained in:
@@ -10,4 +10,48 @@ describe RelatedContentsController do
|
|||||||
end.to raise_error ActiveRecord::RecordNotFound
|
end.to raise_error ActiveRecord::RecordNotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#score_positive" do
|
||||||
|
it "increases the score of both the related content and its opposite" do
|
||||||
|
user = create(:user, :level_two)
|
||||||
|
related_content = create(:related_content, author: create(:user))
|
||||||
|
opposite_content = related_content.opposite_related_content
|
||||||
|
|
||||||
|
sign_in user
|
||||||
|
|
||||||
|
put :score_positive, params: { id: related_content, format: :js }
|
||||||
|
|
||||||
|
score = related_content.related_content_scores
|
||||||
|
.find_by(user: user, related_content: related_content)
|
||||||
|
.value
|
||||||
|
opposite_score = opposite_content.related_content_scores
|
||||||
|
.find_by(user: user, related_content: opposite_content)
|
||||||
|
.value
|
||||||
|
|
||||||
|
expect(score).to eq(1)
|
||||||
|
expect(opposite_score).to eq(1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#score_negative" do
|
||||||
|
it "decreases the score of both the related content and its opposite" do
|
||||||
|
user = create(:user, :level_two)
|
||||||
|
related_content = create(:related_content, author: create(:user))
|
||||||
|
opposite_content = related_content.opposite_related_content
|
||||||
|
|
||||||
|
sign_in user
|
||||||
|
|
||||||
|
put :score_negative, params: { id: related_content, format: :js }
|
||||||
|
|
||||||
|
score = related_content.related_content_scores
|
||||||
|
.find_by(user: user, related_content: related_content)
|
||||||
|
.value
|
||||||
|
opposite_score = opposite_content.related_content_scores
|
||||||
|
.find_by(user: user, related_content: opposite_content)
|
||||||
|
.value
|
||||||
|
|
||||||
|
expect(score).to eq(-1)
|
||||||
|
expect(opposite_score).to eq(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ shared_examples "relationable" do |relationable_model_name|
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "related content can be scored positively" do
|
scenario "related content can be scored positively" do
|
||||||
related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
|
create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit polymorphic_path(relationable)
|
visit polymorphic_path(relationable)
|
||||||
@@ -147,13 +147,10 @@ shared_examples "relationable" do |relationable_model_name|
|
|||||||
expect(page).not_to have_link "Yes"
|
expect(page).not_to have_link "Yes"
|
||||||
expect(page).not_to have_link "No"
|
expect(page).not_to have_link "No"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.id).value).to eq(1)
|
|
||||||
expect(related_content.opposite_related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.opposite_related_content.id).value).to eq(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "related content can be scored negatively" do
|
scenario "related content can be scored negatively" do
|
||||||
related_content = create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
|
create(:related_content, parent_relationable: relationable, child_relationable: related1, author: build(:user))
|
||||||
|
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit polymorphic_path(relationable)
|
visit polymorphic_path(relationable)
|
||||||
@@ -164,9 +161,6 @@ shared_examples "relationable" do |relationable_model_name|
|
|||||||
expect(page).not_to have_link "Yes"
|
expect(page).not_to have_link "Yes"
|
||||||
expect(page).not_to have_link "No"
|
expect(page).not_to have_link "No"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.id).value).to eq(-1)
|
|
||||||
expect(related_content.opposite_related_content.related_content_scores.find_by(user_id: user.id, related_content_id: related_content.opposite_related_content.id).value).to eq(-1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "if related content has negative score it will be hidden" do
|
scenario "if related content has negative score it will be hidden" do
|
||||||
|
|||||||
Reference in New Issue
Block a user