Refactored proposal. Enabled cancancan

This commit is contained in:
Henne Vogelsang 2014-07-23 16:24:05 +02:00
parent 0ae7991943
commit c982cbb88a
13 changed files with 204 additions and 231 deletions

View file

@ -11,7 +11,7 @@ feature Event do
feature: true, js: true do
admin = create(:admin, email: 'admin@example.com')
participant = create(:participant, email: 'participant@example.com')
participant = create(:participant, email: 'participant@example.com', biography: "")
expected_count = Event.count + 1
conference = create(:conference)
@ -37,9 +37,8 @@ feature Event do
fill_in 'event_media_id', with: '123456'
fill_in 'user_biography', with: 'Lorem ipsum biography'
fill_in 'user_name', with: 'Example User'
click_button 'Submit Session'
click_button 'Create Event'
expect(current_path).to eq(register_conference_path(conference.short_title))
expect(Event.count).to eq(expected_count)
@ -77,7 +76,7 @@ feature Event do
expect(page.has_content?('Unconfirmed')).to be true
click_link "confirm_proposal_#{event.id}"
expect(flash).
to eq('Event was confirmed. Please register to attend the conference.')
to eq('The proposal was confirmed. Please register to attend the conference.')
# Register for conference
find('#register').click
@ -87,7 +86,7 @@ feature Event do
visit conference_proposal_index_path(conference.short_title)
expect(page.has_content?('Confirmed')).to be true
click_link "delete_proposal_#{event.id}"
expect(flash).to eq('Proposal withdrawn.')
expect(flash).to eq('Proposal was successfully withdrawn.')
end
end

View file

@ -0,0 +1,39 @@
require 'spec_helper'
require "cancan/matchers"
describe "User" do
describe "abilities" do
subject(:ability){ Ability.new(user) }
let(:user){ nil }
context "when is an admin" do
let!(:user) { create(:admin) }
it{ should be_able_to(:manage, Event.new) }
end
context "when is an participant" do
let(:user) { build(:participant) }
it{ should_not be_able_to(:manage, Event.new) }
it{ should be_able_to(:create, Event.new) }
it{ should be_able_to(:read, Event.new) }
end
context "when is an event owner" do
let(:user) { create(:participant) }
let(:user2) { create(:participant) }
let(:myevent) { create(:event, users: [user]) }
let(:someevent) { create(:event, users: [user2]) }
# Users are able to update and destroy their own events
it{ should be_able_to(:update, myevent) }
it{ should be_able_to(:destroy, myevent) }
# Users are not able to update and destroy other users events
it{ should_not be_able_to(:update, someevent) }
it{ should_not be_able_to(:destroy, someevent) }
end
end
end