Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Mar 8, 2012
1 parent e5f9f44 commit e80992d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions features/step_definitions/calendar_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
end

Given /^I am an admin(?:istrator)? of "([^\"]*)"$/ do |calendar|
cal = Calendar.find_by_name(calendar) || FactoryGirl.create(:calendar, :name => calendar)
cal = fetch_calendar calendar
FactoryGirl.create :permission, :user => UserSession.find.record, :calendar => cal, :role => FactoryGirl.create(:admin_role)
end

Given /^someone else has a calendar called "([^\"]*)"$/ do |calendar|
cal = Calendar.find_by_name(calendar) || FactoryGirl.create(:calendar, :name => calendar)
cal = fetch_calendar calendar
Permission.destroy(cal.permissions.find_all_by_user_id(User.current_user.id).collect(&:id)) # make sure we don't have any superfluous admin permissions hanging around
Factory :admin_permission, :calendar => cal
end
Expand All @@ -29,12 +29,12 @@

Then /^I should be an admin(?:istrator)? of "([^\"]*)"$/ do |calendar|
admin = Role.find_or_create_by_name('admin')
cal = Calendar.find_by_name(calendar)
cal = fetch_calendar calendar
User.current_user.permissions.find_by_calendar_id_and_role_id(cal.id, admin.id).should_not be_nil
end

Then /^I should (not )?be subscribed to "([^"]*)"$/ do |negation, calendar|
calendar = Calendar.find_by_name(calendar)
calendar = fetch_calendar calendar
user = User.current_user
permission = user.permissions.find_by_calendar_id(calendar)
if negation
Expand Down
7 changes: 7 additions & 0 deletions features/support/fetch_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module FetchHelpers
def fetch_calendar(name)
Calendar.find_by_name(calendar) || Factory(:calendar, :name => calendar)
end
end

World FetchHelpers

0 comments on commit e80992d

Please sign in to comment.