Skip to content

Commit

Permalink
debates can be edited up to 48 hours since created
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoorai2000 committed Nov 17, 2015
1 parent 0277106 commit cce5524
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/debate.rb
Expand Up @@ -74,7 +74,7 @@ def total_anonymous_votes
end

def editable?
total_votes <= Setting.value_for('max_votes_for_debate_edit').to_i
created_at > 48.hours.ago
end

def editable_by?(user)
Expand Down
17 changes: 7 additions & 10 deletions spec/models/debate_spec.rb
Expand Up @@ -81,25 +81,22 @@
end

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)
it "should be true if debate was created now" do
debate = create(:debate, created_at: Time.now)
expect(debate.editable?).to be true
end

it "should be true if debate has less than limit votes" do
create_list(:vote, 2, votable: debate)
expect(debate.total_votes).to eq(2)
it "should be true if debate was created less than 48 hours ago" do
debate = create(:debate, created_at: 47.hours.ago)
expect(debate.editable?).to be true
end

it "should be false if debate has more than limit votes" do
create_list(:vote, 4, votable: debate)
expect(debate.total_votes).to eq(4)
it "should be false if debate was created more than 48 hours ago" do
debate = create(:debate, created_at: 49.hours.ago)
expect(debate.editable?).to be false
end

end

describe "#editable_by?" do
Expand Down

0 comments on commit cce5524

Please sign in to comment.