Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Feature trying to duplicate Nick's issue, unlucky.

  • Loading branch information...
commit 357d7bad4096de594306f986f0230e16272ffa44 1 parent 64ab52a
@radar authored
View
22 features/category_access_permissions.feature
@@ -0,0 +1,22 @@
+Feature: Category access permissions
+ In order to duplicate the issue Nick Crowther reported on 11th November, 2009
+ As a developer
+ I want this feature to ensure it never happens again
+
+ Scenario: Category permissions should be enforced
+ Given there is Nick Crowther's setup
+ And I am logged in as "Nick"
+ And I am on the homepage
+ Then I should see "Category One"
+ And I should see "Forum One"
+ And I should not see "Category Two"
+ And I should not see "Forum Two"
+
+ When I follow "Logout"
+
+ Given I am logged in as "Ryan"
+ And I am on the homepage
+ Then I should see "Category Two"
+ And I should see "Forum Two"
+ And I should not see "Category One"
+ And I should not see "Forum One"
View
2  features/step_definitions/app_steps.rb
@@ -21,4 +21,4 @@
User.make_with_group(:registered_user, "Registered Users")
Forum.make(:public_forum)
-end
+end
View
29 features/step_definitions/regression_steps.rb
@@ -0,0 +1,29 @@
+Given /^there is Nick Crowther's setup$/ do
+ Forum.delete_all
+ Group.delete_all
+ Permission.delete_all
+ User.delete_all
+ Category.delete_all
+
+ category_1 = Category.make(:name => "Category One")
+ category_1.forums.make(:title => "Forum One")
+
+ category_2 = Category.make(:name => "Category Two")
+ category_2.forums.make(:title => "Forum Two")
+
+ # The anonymous user
+ User.make_with_group(:anonymous, "Anonymous")
+
+ # The registered user
+ User.make_with_group(:registered_user, "Registered Users")
+
+ User.make_with_group(:nick, { :name => "Group One" }, {:login => "Nick"})
+ User.make_with_group(:ryan, { :name => "Group Two" }, {:login => "Ryan"})
+
+ group_1 = Group.find_by_name("Group One")
+ group_2 = Group.find_by_name("Group Two")
+
+
+ Permission.make(:can_see_category => true, :group => group_1, :category => category_1)
+ Permission.make(:can_see_category => true, :group => group_2, :category => category_2)
+end
View
6 features/support/env.rb
@@ -4,9 +4,9 @@
require this + '/../../config/environment'
require 'cucumber/rails/world'
require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support
-Cucumber::Rails.use_transactional_fixtures
-Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
- # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
+# Cucumber::Rails.use_transactional_fixtures
+# Cucumber::Rails.bypass_rescue # Comment out this line if you want Rails own error handling
+# # (e.g. rescue_action_in_public / rescue_responses / rescue_from)
this = File.expand_path(File.dirname(__FILE__))
require File.join(this, 'blueprints')
View
8 features/support/ext/group_ext.rb
@@ -1,8 +1,10 @@
class Group < ActiveRecord::Base
# Ensures there's always a group with that name, and ideally only one.
- def self.ensure(name)
+ def self.ensure(name_or_attributes)
# Wouldn't have to do the gsub if Rails correctly underscored strings like "Registered User"
- group = Group.find_by_name(name)
- group ||= Group.make(name.gsub(" ", "").underscore.to_sym)
+ group = Group.find_by_name(name_or_attributes) if name_or_attributes.is_a?(String)
+
+ group ||= Group.make(name_or_attributes.is_a?(String) ? name_or_attributes.gsub(" ", "").underscore.to_sym : name_or_attributes)
+ group
end
end
View
4 features/support/ext/user_ext.rb
@@ -6,8 +6,8 @@ def self.ensure(login)
end
# Shame that I have to do this...
- def self.make_with_group(name, group)
- u = User.new(User.plan(name))
+ def self.make_with_group(name, group, attrs={})
+ u = User.new(User.plan(name).merge(attrs))
u.groups << Group.ensure(group)
u.save
u
Please sign in to comment.
Something went wrong with that request. Please try again.