Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #201 from zsombor/master
Browse files Browse the repository at this point in the history
Missing Ability specs on Comments.
  • Loading branch information
mezis committed Feb 10, 2014
2 parents 988df43 + 4b912e8 commit 4ce6097
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
58 changes: 58 additions & 0 deletions spec/models/ability_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require "spec_helper"
require "cancan/matchers"


describe Ability do
fixtures :users, :accounts, :logins
before { Idea.delete_all }

describe "comments" do
let(:current_user) { users(:abigale_balisteri) }
subject { described_class.new current_user }

context "permissions when comment belongs to someone else" do
let(:comment) { Comment.make!(author: someone_else) }
let(:someone_else) { users(:joseph_fourier)}

it "cannot update comment made by someone else" do
should_not be_able_to(:update, comment)
end

it "cannot destroy comment made by someone else" do
should_not be_able_to(:destroy, comment)
end

it "can vote on comment made by someone else" do
should be_able_to(:vote, comment)
end
end

context "permissions on comments made by the current user" do
let(:comment) { Comment.make!(author: current_user) }
it "can update recent comment" do
should be_able_to(:update, comment)
end

it "can destroy recent comment" do
should be_able_to(:destroy, comment)
end

it "cannot vote on her own comments" do
should_not be_able_to(:vote, comment)
end
end

context "permissions on old comments made by the current user" do
let(:comment) { Comment.make!(author: current_user, created_at: 1.week.ago) }
it "cannot update old comment" do
should_not be_able_to(:update, comment)
end

it "cannot destroy old comment" do
should_not be_able_to(:destroy, comment)
end
end
end

# TODO describe Idea and other permissions here.
end
3 changes: 2 additions & 1 deletion spec/services/idea_mover_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'

describe IdeaMoverService do
fixtures :users, :accounts, :logins
subject { described_class.new(idea:@idea, account:@account) }
let(:perform) { subject.run }

Expand All @@ -11,7 +12,7 @@
it 'borks if idea already in target account' do
@idea = Idea.make!
@account = @idea.account
expect { perform }.to raise_exception(ArgumentError)
expect { perform }.to raise_exception(ArgumentError)
end

context '(with idea and account)' do
Expand Down
8 changes: 8 additions & 0 deletions spec/support/fixtures/logins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ abigale:
email: abigale_hudson@legros.name
encrypted_password: $2a$04$q..mejuOgGcE5.ZWxae51uim0fkFiMIlrDUm9kkNGBJ3pin0DEBKC
sign_in_count: 0
fourier:
first_name: Joseph
last_name: Fourier
created_at: 2013-05-13 10:19:04.000000000 Z
updated_at: 2013-05-13 10:19:04.000000000 Z
email: joseph.fourier@auxerre.name
encrypted_password: $2a$04$q..mejuOgGcE5.ZWxae51uim0fkFiMIlrDUm9kkNGBJ3pin0DEBKC
sign_in_count: 0
8 changes: 8 additions & 0 deletions spec/support/fixtures/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ abigale_balisteri:
created_at: 2013-05-13 10:19:04.000000000 Z
updated_at: 2013-05-13 10:19:04.000000000 Z
state: 0
joseph_fourier:
login: fourier
account: balisteri
karma: 20
voting_power: 1
created_at: 2013-05-13 10:19:04.000000000 Z
updated_at: 2013-05-13 10:19:04.000000000 Z
state: 0

0 comments on commit 4ce6097

Please sign in to comment.