adds tests for debate editable with max votes

This commit is contained in:
David Gil
2015-09-15 21:28:01 +02:00
parent f231104edc
commit 42f1ffb171
2 changed files with 15 additions and 5 deletions

View File

@@ -244,7 +244,9 @@ feature 'Debates' do
scenario 'Update should not be posible if debate is not editable' do
debate = create(:debate)
create(:vote, votable: debate)
Setting.find_by(key: "max_votes_for_debate_edit").update(value: 2)
3.times { create(:vote, votable: debate) }
expect(debate).to_not be_editable
login_as(debate.author)

View File

@@ -48,28 +48,36 @@ describe Debate do
describe "#editable?" do
let(:debate) { create(:debate) }
before(:each) { Setting.find_by(key: "max_votes_for_debate_edit").update(value: 3) }
it "should be true if debate has no votes yet" do
expect(debate.total_votes).to eq(0)
expect(debate.editable?).to be true
end
it "should be false if debate has votes" do
create(:vote, votable: debate)
expect(debate.total_votes).to eq(1)
it "should be true if proposal has less than limit votes" do
create_list(:vote, 2, votable: debate)
expect(debate.total_votes).to eq(2)
expect(debate.editable?).to be true
end
it "should be false if proposal has more than limit votes" do
create_list(:vote, 4, votable: debate)
expect(debate.total_votes).to eq(4)
expect(debate.editable?).to be false
end
end
describe "#editable_by?" do
let(:debate) { create(:debate) }
before(:each) { Setting.find_by(key: "max_votes_for_debate_edit").update(value: 1) }
it "should be true if user is the author and debate is editable" do
expect(debate.editable_by?(debate.author)).to be true
end
it "should be false if debate is not editable" do
create(:vote, votable: debate)
create_list(:vote, 2, votable: debate)
expect(debate.editable_by?(debate.author)).to be false
end