devisable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Devisable.gemspec +117 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +111 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/generators/devisable/USAGE +57 -0
- data/lib/generators/devisable/devisable_generator.rb +484 -0
- data/lib/generators/devisable/templates/app/controllers/registrations_controller.erb +19 -0
- data/lib/generators/devisable/templates/app/controllers/users_controller.erb +152 -0
- data/lib/generators/devisable/templates/app/controllers/welcome_controller.erb +11 -0
- data/lib/generators/devisable/templates/app/helpers/roles_helper.erb +63 -0
- data/lib/generators/devisable/templates/app/models/permission.erb +12 -0
- data/lib/generators/devisable/templates/app/models/role.erb +5 -0
- data/lib/generators/devisable/templates/app/views/roles/_form.erb +29 -0
- data/lib/generators/devisable/templates/app/views/roles/edit.erb +6 -0
- data/lib/generators/devisable/templates/app/views/roles/index.erb +28 -0
- data/lib/generators/devisable/templates/app/views/roles/new.erb +5 -0
- data/lib/generators/devisable/templates/app/views/roles/show.erb +10 -0
- data/lib/generators/devisable/templates/app/views/shared/_admin_nav.erb +7 -0
- data/lib/generators/devisable/templates/app/views/users/_form.erb +23 -0
- data/lib/generators/devisable/templates/app/views/users/edit.erb +6 -0
- data/lib/generators/devisable/templates/app/views/users/index.erb +27 -0
- data/lib/generators/devisable/templates/app/views/users/new.erb +5 -0
- data/lib/generators/devisable/templates/app/views/users/show.erb +55 -0
- data/lib/generators/devisable/templates/app/views/welcome/welcome_index.erb +3 -0
- data/lib/generators/devisable/templates/config/initializers/devise_initializer.erb +239 -0
- data/lib/generators/devisable/templates/cucumber/_rake_partial.rb +19 -0
- data/lib/generators/devisable/templates/cucumber/devise.feature +78 -0
- data/lib/generators/devisable/templates/cucumber/role.feature +79 -0
- data/lib/generators/devisable/templates/cucumber/step_definitions/authentication_steps.rb +33 -0
- data/lib/generators/devisable/templates/cucumber/step_definitions/generic_steps.rb +23 -0
- data/lib/generators/devisable/templates/cucumber/step_definitions/role_steps.rb +32 -0
- data/lib/generators/devisable/templates/cucumber/step_definitions/user_steps.rb +30 -0
- data/lib/generators/devisable/templates/cucumber/support/_env_partial.rb +57 -0
- data/lib/generators/devisable/templates/cucumber/support/_paths_partial.rb +20 -0
- data/lib/generators/devisable/templates/cucumber/user.feature +45 -0
- data/lib/generators/devisable/templates/partials/_ability_class.rb +53 -0
- data/lib/generators/devisable/templates/partials/_access_denied_flash.rb +4 -0
- data/lib/generators/devisable/templates/partials/_accessible_permissions_controller.rb +8 -0
- data/lib/generators/devisable/templates/partials/_accessible_permissions_model.rb +43 -0
- data/lib/generators/devisable/templates/partials/_application_controller_methods.erb +3 -0
- data/lib/generators/devisable/templates/partials/_application_controller_methods2.erb +11 -0
- data/lib/generators/devisable/templates/partials/_application_current_tab.rb +8 -0
- data/lib/generators/devisable/templates/partials/_application_flash.html.erb +4 -0
- data/lib/generators/devisable/templates/partials/_environments_development.erb +10 -0
- data/lib/generators/devisable/templates/partials/_login_links.erb +18 -0
- data/lib/generators/devisable/templates/partials/_migration_down.rb +2 -0
- data/lib/generators/devisable/templates/partials/_migration_up.rb +7 -0
- data/lib/generators/devisable/templates/partials/_oauth_user_table_fields.erb +1 -0
- data/lib/generators/devisable/templates/partials/_permission_equals.rb +8 -0
- data/lib/generators/devisable/templates/partials/_permission_manage.js +18 -0
- data/lib/generators/devisable/templates/partials/_role_permission.rb +72 -0
- data/lib/generators/devisable/templates/partials/_roles_index_delete.erb +7 -0
- data/lib/generators/devisable/templates/partials/_user_model_methods.erb +21 -0
- data/lib/generators/devisable/templates/partials/_user_role.rb +7 -0
- data/lib/generators/devisable/templates/spec/helpers/roles_helper_spec.erb +50 -0
- data/lib/generators/devisable/templates/spec/models/ability_spec.erb +69 -0
- data/lib/generators/devisable/templates/spec/models/permission_spec.erb +22 -0
- data/lib/generators/devisable/templates/spec/models/role_spec.erb +45 -0
- data/lib/generators/devisable/templates/spec/models/user_spec.erb +65 -0
- data/pkg/devisable-0.1.0.gem +0 -0
- data/pkg/devise_generator-0.1.0.gem +0 -0
- data/test/helper.rb +18 -0
- data/test/test_devise_generator.rb +7 -0
- metadata +169 -0
@@ -0,0 +1,3 @@
|
|
1
|
+
<h1>Site #1</h1>
|
2
|
+
|
3
|
+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
@@ -0,0 +1,239 @@
|
|
1
|
+
require 'warden_oauth'
|
2
|
+
|
3
|
+
Devise.setup do |config|
|
4
|
+
# ==> Mailer Configuration
|
5
|
+
# Configure the e-mail address which will be shown in DeviseMailer.
|
6
|
+
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
7
|
+
|
8
|
+
# Configure the class responsible to send e-mails.
|
9
|
+
# config.mailer = "Devise::Mailer"
|
10
|
+
|
11
|
+
# ==> ORM configuration
|
12
|
+
# Load and configure the ORM. Supports :active_record (default) and
|
13
|
+
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
14
|
+
# available as additional gems.
|
15
|
+
require 'devise/orm/active_record'
|
16
|
+
|
17
|
+
# ==> Configuration for any authentication mechanism
|
18
|
+
# Configure which keys are used when authenticating an user. By default is
|
19
|
+
# just :email. You can configure it to use [:username, :subdomain], so for
|
20
|
+
# authenticating an user, both parameters are required. Remember that those
|
21
|
+
# parameters are used only when authenticating and not when retrieving from
|
22
|
+
# session. If you need permissions, you should implement that in a before filter.
|
23
|
+
# config.authentication_keys = [ :email ]
|
24
|
+
|
25
|
+
# Tell if authentication through request.params is enabled. True by default.
|
26
|
+
# config.params_authenticatable = true
|
27
|
+
|
28
|
+
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
29
|
+
# config.http_authenticatable = false
|
30
|
+
|
31
|
+
# Set this to true to use Basic Auth for AJAX requests. True by default.
|
32
|
+
# config.http_authenticatable_on_xhr = true
|
33
|
+
|
34
|
+
# The realm used in Http Basic Authentication
|
35
|
+
# config.http_authentication_realm = "Application"
|
36
|
+
|
37
|
+
# ==> Configuration for :database_authenticatable
|
38
|
+
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
39
|
+
# using other encryptors, it sets how many times you want the password re-encrypted.
|
40
|
+
config.stretches = 10
|
41
|
+
|
42
|
+
# Define which will be the encryption algorithm. Devise also supports encryptors
|
43
|
+
# from others authentication tools as :clearance_sha1, :authlogic_sha512 (then
|
44
|
+
# you should set stretches above to 20 for default behavior) and :restful_authentication_sha1
|
45
|
+
# (then you should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
|
46
|
+
config.encryptor = :bcrypt
|
47
|
+
|
48
|
+
# Setup a pepper to generate the encrypted password.
|
49
|
+
config.pepper = "0ce0024d92881b05c5148aff8fc230f28dea8eaa889556cf2a0ec12890c620137e4ed8eb5bd1a60536dddf655405c7b00ede21e6414994193f3ff9de940035d1"
|
50
|
+
|
51
|
+
# ==> Configuration for :confirmable
|
52
|
+
# The time you want to give your user to confirm his account. During this time
|
53
|
+
# he will be able to access your application without confirming. Default is nil.
|
54
|
+
# When confirm_within is zero, the user won't be able to sign in without confirming.
|
55
|
+
# You can use this to let your user access some features of your application
|
56
|
+
# without confirming the account, but blocking it after a certain period
|
57
|
+
# (ie 2 days).
|
58
|
+
# config.confirm_within = 2.days
|
59
|
+
|
60
|
+
# ==> Configuration for :rememberable
|
61
|
+
# The time the user will be remembered without asking for credentials again.
|
62
|
+
# config.remember_for = 2.weeks
|
63
|
+
|
64
|
+
# If true, a valid remember token can be re-used between multiple browsers.
|
65
|
+
# config.remember_across_browsers = true
|
66
|
+
|
67
|
+
# If true, extends the user's remember period when remembered via cookie.
|
68
|
+
# config.extend_remember_period = false
|
69
|
+
|
70
|
+
# ==> Configuration for :validatable
|
71
|
+
# Range for password length
|
72
|
+
# config.password_length = 6..20
|
73
|
+
|
74
|
+
# Regex to use to validate the email address
|
75
|
+
# config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
|
76
|
+
|
77
|
+
# ==> Configuration for :timeoutable
|
78
|
+
# The time you want to timeout the user session without activity. After this
|
79
|
+
# time the user will be asked for credentials again.
|
80
|
+
# config.timeout_in = 10.minutes
|
81
|
+
|
82
|
+
# ==> Configuration for :lockable
|
83
|
+
# Defines which strategy will be used to lock an account.
|
84
|
+
# :failed_attempts = Locks an account after a number of failed attempts to sign in.
|
85
|
+
# :none = No lock strategy. You should handle locking by yourself.
|
86
|
+
# config.lock_strategy = :failed_attempts
|
87
|
+
|
88
|
+
# Defines which strategy will be used to unlock an account.
|
89
|
+
# :email = Sends an unlock link to the user email
|
90
|
+
# :time = Re-enables login after a certain amount of time (see :unlock_in below)
|
91
|
+
# :both = Enables both strategies
|
92
|
+
# :none = No unlock strategy. You should handle unlocking by yourself.
|
93
|
+
# config.unlock_strategy = :both
|
94
|
+
|
95
|
+
# Number of authentication tries before locking an account if lock_strategy
|
96
|
+
# is failed attempts.
|
97
|
+
# config.maximum_attempts = 20
|
98
|
+
|
99
|
+
# Time interval to unlock the account if :time is enabled as unlock_strategy.
|
100
|
+
# config.unlock_in = 1.hour
|
101
|
+
|
102
|
+
# ==> Configuration for :token_authenticatable
|
103
|
+
# Defines name of the authentication token params key
|
104
|
+
# config.token_authentication_key = :auth_token
|
105
|
+
|
106
|
+
# ==> Scopes configuration
|
107
|
+
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
108
|
+
# "users/sessions/new". It's turned off by default because it's slower if you
|
109
|
+
# are using only default views.
|
110
|
+
# config.scoped_views = true
|
111
|
+
|
112
|
+
# Configure the default scope given to Warden. By default it's the first
|
113
|
+
# devise role declared in your routes.
|
114
|
+
# config.default_scope = :user
|
115
|
+
|
116
|
+
# Configure sign_out behavior.
|
117
|
+
# By default sign_out is scoped (i.e. /users/sign_out affects only :user scope).
|
118
|
+
# In case of sign_out_all_scopes set to true any logout action will sign out all active scopes.
|
119
|
+
# config.sign_out_all_scopes = false
|
120
|
+
|
121
|
+
# ==> Navigation configuration
|
122
|
+
# Lists the formats that should be treated as navigational. Formats like
|
123
|
+
# :html, should redirect to the sign in page when the user does not have
|
124
|
+
# access, but formats like :xml or :json, should return 401.
|
125
|
+
# If you have any extra navigational formats, like :iphone or :mobile, you
|
126
|
+
# should add them to the navigational formats lists. Default is [:html]
|
127
|
+
# config.navigational_formats = [:html, :iphone]
|
128
|
+
|
129
|
+
# ==> Warden configuration
|
130
|
+
# If you want to use other strategies, that are not (yet) supported by Devise,
|
131
|
+
# you can configure them inside the config.warden block. The example below
|
132
|
+
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
133
|
+
#
|
134
|
+
|
135
|
+
config.warden do |manager|
|
136
|
+
#twitter
|
137
|
+
manager.oauth(:twitter) do |twitter|
|
138
|
+
twitter.consumer_key = TWITTER_CONSUMER_KEY
|
139
|
+
twitter.consumer_secret = TWITTER_CONSUMER_SECRET
|
140
|
+
twitter.options({
|
141
|
+
:site => 'http://twitter.com',
|
142
|
+
:oauth_callback => (BASE_URL.end_with?('/') ? BASE_URL[0..-2] : BASE_URL) + '/users',
|
143
|
+
:oauth_callback_confirmed => 'true'
|
144
|
+
})
|
145
|
+
end
|
146
|
+
manager.default_strategies(:scope => :user).unshift :twitter_oauth
|
147
|
+
|
148
|
+
#facebook
|
149
|
+
manager.oauth2(:facebook) do |fb|
|
150
|
+
fb.consumer_key = FACEBOOK_CONSUMER_KEY
|
151
|
+
fb.consumer_secret = FACEBOOK_CONSUMER_SECRET
|
152
|
+
fb.client_id = FACEBOOK_CLIENT_ID
|
153
|
+
fb.options({
|
154
|
+
:authorize_url => 'https://www.facebook.com/dialog/oauth',
|
155
|
+
:access_token_url => 'https://graph.facebook.com/oauth/access_token',
|
156
|
+
:site => 'https://graph.facebook.com',
|
157
|
+
:scope => 'email,offline_access',
|
158
|
+
:redirect_uri => (BASE_URL.end_with?('/') ? BASE_URL[0..-2] : BASE_URL) + '/users'
|
159
|
+
})
|
160
|
+
end
|
161
|
+
manager.default_strategies(:scope => :user).unshift :facebook_oauth
|
162
|
+
end
|
163
|
+
|
164
|
+
def find_or_save_oauth_user(options)
|
165
|
+
conditions = {
|
166
|
+
:provider => options[:provider],
|
167
|
+
:username => options[:username],
|
168
|
+
:email => options[:email]
|
169
|
+
}
|
170
|
+
oauth_profile = OauthProfile.find(:first, :conditions => conditions) || OauthProfile.create(conditions)
|
171
|
+
oauth_profile.token = options[:token]
|
172
|
+
oauth_profile.secret = options[:secret]
|
173
|
+
oauth_profile.name = options[:name]
|
174
|
+
oauth_profile.img_url = options[:img_url]
|
175
|
+
if oauth_profile.user
|
176
|
+
oauth_profile.save
|
177
|
+
user = oauth_profile.user
|
178
|
+
user.email = options[:email] if user.email.blank?
|
179
|
+
user.username = options[:username] if user.username.blank?
|
180
|
+
user.default_provider = options[:provider]
|
181
|
+
user.save
|
182
|
+
else
|
183
|
+
user_fields = {
|
184
|
+
:email => options[:email],
|
185
|
+
:username => options[:username],
|
186
|
+
:authentication_token => access_token.token,
|
187
|
+
:default_provider => options[:provider]
|
188
|
+
}
|
189
|
+
user = User.create(user_fields)
|
190
|
+
user.oauth_profiles << oauth_profile
|
191
|
+
user.save
|
192
|
+
if user.respond_to?('confirm!')
|
193
|
+
user.confirm!
|
194
|
+
end
|
195
|
+
end
|
196
|
+
if user.roles.empty?
|
197
|
+
user.roles << Role.find_by_id(3) unless User.count() == 1
|
198
|
+
end
|
199
|
+
user
|
200
|
+
end
|
201
|
+
|
202
|
+
Warden::OAuth.access_token_user_finder(:twitter) do |access_token|
|
203
|
+
conditions = {:token => access_token.token, :secret => access_token.secret}
|
204
|
+
client = TwitterOAuth::Client.new(
|
205
|
+
:consumer_key => TWITTER_CONSUMER_KEY,
|
206
|
+
:consumer_secret => TWITTER_CONSUMER_SECRET,
|
207
|
+
:token => access_token.token,
|
208
|
+
:secret => access_token.secret
|
209
|
+
)
|
210
|
+
if client.authorized?
|
211
|
+
options = {
|
212
|
+
:provider => 'twitter',
|
213
|
+
:token => access_token.token,
|
214
|
+
:secret => access_token.secret,
|
215
|
+
:username => client.user.first['user']['screen_name'],
|
216
|
+
:email => '',
|
217
|
+
:name => client.user.first['user']['name'],
|
218
|
+
:img_url => client.user.first['user']['profile_image_url'],
|
219
|
+
}
|
220
|
+
user = find_or_save_oauth_user(options)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
Warden::OAuth2.access_token_user_finder(:facebook) do |access_token|
|
226
|
+
user_data = JSON.parse(access_token.get('https://graph.facebook.com/me'))
|
227
|
+
options = {
|
228
|
+
:provider => 'facebook',
|
229
|
+
:token => access_token.token,
|
230
|
+
:secret => '',
|
231
|
+
:username => user_data['name'],
|
232
|
+
:email => user_data['email'],
|
233
|
+
:name => user_data['name'],
|
234
|
+
:img_url => 'https://graph.facebook.com/' + user_data['id'] + '/picture',
|
235
|
+
}
|
236
|
+
user = find_or_save_oauth_user(options)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
task :setup_js_with_xvfb do
|
2
|
+
ENV['DISPLAY'] = ":99"
|
3
|
+
%x{Xvfb :99 -ac -screen 0 1024x768x16 2>/dev/null >/dev/null &}
|
4
|
+
%x{firefox --display=:99 2>/dev/null >/dev/null &}
|
5
|
+
end
|
6
|
+
|
7
|
+
task :setup_js_with_vnc4server do
|
8
|
+
ENV['DISPLAY'] = ":99"
|
9
|
+
%x{vncserver :99 2>/dev/null >/dev/null &}
|
10
|
+
%x{DISPLAY=:99 firefox 2>/dev/null >/dev/null &}
|
11
|
+
end
|
12
|
+
|
13
|
+
task :kill_js do
|
14
|
+
%x{killall Xvnc4}
|
15
|
+
%x{killall Xvfb}
|
16
|
+
%x{killall firefox}
|
17
|
+
end
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
Feature: Devise login and registration
|
2
|
+
|
3
|
+
Scenario: First User Registration
|
4
|
+
Given there are no users in the system
|
5
|
+
And I have the default roles
|
6
|
+
And I am on the sign up page
|
7
|
+
When I fill in "user@cloudspace.com" for "Email"
|
8
|
+
And I fill in "password" for "Password"
|
9
|
+
And I fill in "password" for "Password confirmation"
|
10
|
+
And I press "Sign up"
|
11
|
+
Then I should be on the homepage
|
12
|
+
And I should have the role "SuperAdmin"
|
13
|
+
|
14
|
+
Scenario: Nonfirst User Registration
|
15
|
+
Given there are users in the system
|
16
|
+
And I have the default roles
|
17
|
+
And I am on the sign up page
|
18
|
+
When I fill in "user@cloudspace.com" for "Email"
|
19
|
+
And I fill in "password" for "Password"
|
20
|
+
And I fill in "password" for "Password confirmation"
|
21
|
+
And I press "Sign up"
|
22
|
+
Then I should be on the homepage
|
23
|
+
And I should have the role "GeneralUser"
|
24
|
+
|
25
|
+
Scenario: User Sign In
|
26
|
+
Given I am signed in as "user@cloudspace.com"
|
27
|
+
|
28
|
+
Scenario: User Sign Out
|
29
|
+
Given I am signed in as "user@cloudspace.com"
|
30
|
+
Given I am signed out
|
31
|
+
|
32
|
+
Scenario: User Sign In With Bad Password
|
33
|
+
Given I am signed in as "user@cloudspace.com"
|
34
|
+
And I am signed out
|
35
|
+
And I am on the sign in page
|
36
|
+
When I fill in "user@cloudspace.com" for "Email"
|
37
|
+
And I fill in "badpass" for "Password"
|
38
|
+
And I press "Sign in"
|
39
|
+
Then I should be on the sign in page
|
40
|
+
And I should see "Invalid email or password"
|
41
|
+
|
42
|
+
Scenario: Lost Password Page
|
43
|
+
Given I am signed in as "user@cloudspace.com"
|
44
|
+
And I am signed out
|
45
|
+
And I am on the forgot password page
|
46
|
+
When I fill in "user@cloudspace.com" for "Email"
|
47
|
+
And I press "Send me reset password instructions"
|
48
|
+
Then I should be on the sign in page
|
49
|
+
And I should see "You will receive an email with instructions about how to reset your password in a few minutes."
|
50
|
+
|
51
|
+
Scenario: Lost Password Page Bad Email Address
|
52
|
+
Given I am signed in as "user@cloudspace.com"
|
53
|
+
And I am signed out
|
54
|
+
And I am on the forgot password page
|
55
|
+
When I fill in "baduser@cloudspace.com" for "Email"
|
56
|
+
And I press "Send me reset password instructions"
|
57
|
+
Then I should be on the forgot password submitted page
|
58
|
+
And I should see "Email not found"
|
59
|
+
|
60
|
+
Scenario: Lost Password Page Missing Email Address
|
61
|
+
Given I am signed in as "user@cloudspace.com"
|
62
|
+
And I am signed out
|
63
|
+
And I am on the forgot password page
|
64
|
+
When I press "Send me reset password instructions"
|
65
|
+
Then I should be on the forgot password submitted page
|
66
|
+
And I should see "Email can't be blank"
|
67
|
+
|
68
|
+
Scenario: Login Link
|
69
|
+
Given I am on the homepage
|
70
|
+
When I follow "Login" within "body"
|
71
|
+
Then I should be on the sign in page
|
72
|
+
|
73
|
+
Scenario: Logout Link
|
74
|
+
Given I am signed in as "user@cloudspace.com"
|
75
|
+
And I am on the homepage
|
76
|
+
When I follow "Logout"
|
77
|
+
And I should be on the homepage
|
78
|
+
And I should see "Signed out successfully."
|
@@ -0,0 +1,79 @@
|
|
1
|
+
Feature: Manage Roles
|
2
|
+
|
3
|
+
Scenario: Viewing Roles as a SuperAdmin
|
4
|
+
Given I am signed in as "user@cloudspace.com"
|
5
|
+
And I only have the role "SuperAdmin"
|
6
|
+
When I go to the roles page
|
7
|
+
Then I should see "SuperAdmin"
|
8
|
+
And I should see "Show"
|
9
|
+
And I should see "Edit"
|
10
|
+
And I should see "Destroy"
|
11
|
+
|
12
|
+
Scenario: Viewing Roles as a GeneralUser
|
13
|
+
Given I am signed in as "user@cloudspace.com"
|
14
|
+
And I only have the role "GeneralUser"
|
15
|
+
When I go to the roles page
|
16
|
+
Then I should not see "SuperAdmin"
|
17
|
+
And I should not see "Show"
|
18
|
+
And I should not see "Edit"
|
19
|
+
And I should not see "Destroy"
|
20
|
+
|
21
|
+
Scenario: Creating a Role
|
22
|
+
Given I am signed in as "user@cloudspace.com"
|
23
|
+
And I have the role "SuperAdmin"
|
24
|
+
And I am on the roles page
|
25
|
+
When I follow "New Role"
|
26
|
+
And I fill in "Advanced User" for "Name"
|
27
|
+
And I fill in the following checkboxes with categories:
|
28
|
+
| category | permission |
|
29
|
+
| Roles | manage |
|
30
|
+
| Roles | read |
|
31
|
+
| Roles | create |
|
32
|
+
| Users | manage |
|
33
|
+
| Users | read |
|
34
|
+
And I press "Create Role"
|
35
|
+
Then I should be on that role's view page
|
36
|
+
And I should see "Role was successfully created."
|
37
|
+
And I should see "Advanced User"
|
38
|
+
|
39
|
+
Scenario: Editing a Role
|
40
|
+
Given I am signed in as "user@cloudspace.com"
|
41
|
+
And there is only the "SuperAdmin" role in the system
|
42
|
+
And I have the role "SuperAdmin"
|
43
|
+
And I am on the roles page
|
44
|
+
When I follow "Edit"
|
45
|
+
And I fill in "SuperDuperAdmin" for "Name"
|
46
|
+
And I fill in the following checkboxes with categories:
|
47
|
+
| category | permission |
|
48
|
+
| Roles | manage |
|
49
|
+
| Roles | read |
|
50
|
+
| Roles | create |
|
51
|
+
| Roles | update |
|
52
|
+
| Roles | destroy |
|
53
|
+
| Users | manage |
|
54
|
+
| Users | read |
|
55
|
+
| Users | create |
|
56
|
+
| Users | update |
|
57
|
+
| Users | destroy |
|
58
|
+
And I press "Update Role"
|
59
|
+
Then I should be on that role's view page
|
60
|
+
And I should see "Role was successfully updated."
|
61
|
+
And I should see "SuperDuperAdmin"
|
62
|
+
|
63
|
+
Scenario: Deleting a Role
|
64
|
+
Given I am signed in as "user@cloudspace.com"
|
65
|
+
And the "UnnecessaryRole" role has been added to the system
|
66
|
+
And I have the role "SuperAdmin"
|
67
|
+
And I am on the roles page
|
68
|
+
When I follow "Destroy" for "UnnecessaryRole"
|
69
|
+
Then I should be on the roles page
|
70
|
+
And I should see "Role was successfully deleted."
|
71
|
+
And I should not see "UnnecessaryRole"
|
72
|
+
|
73
|
+
Scenario: Deleting a Role With Users Associated
|
74
|
+
Given I am signed in as "user@cloudspace.com"
|
75
|
+
And there is only the "SuperAdmin" role in the system
|
76
|
+
And I have the role "SuperAdmin"
|
77
|
+
And I am on the roles page
|
78
|
+
Then I should see a span with the title "Roles with associated users cannot be deleted"
|
79
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Given /^I am signed in as "(.*)"$/ do |email|
|
2
|
+
@current_user = User.create!(
|
3
|
+
:email => email,
|
4
|
+
:password => 'password',
|
5
|
+
:password_confirmation => 'password',
|
6
|
+
:roles => [Role.create!(:name => 'GeneralUser')]
|
7
|
+
)
|
8
|
+
|
9
|
+
Given %{I am on the sign in page}
|
10
|
+
When %{I fill in "#{email}" for "Email"}
|
11
|
+
And %{I fill in "password" for "Password"}
|
12
|
+
And %{I press "Sign in"}
|
13
|
+
Then %{I should be on the homepage}
|
14
|
+
#And %{I should see "Sign in successful!"}
|
15
|
+
end
|
16
|
+
|
17
|
+
Given /^I have the role "(.*)"$/ do |role|
|
18
|
+
@current_user.roles << Role.create!(
|
19
|
+
:name => role
|
20
|
+
)
|
21
|
+
@current_user.save
|
22
|
+
end
|
23
|
+
|
24
|
+
Given /^I only have the role "(.*)"$/ do |role|
|
25
|
+
@current_user.roles = [ Role.create!( :name => role) ]
|
26
|
+
@current_user.save
|
27
|
+
end
|
28
|
+
|
29
|
+
Given /^I am signed out$/ do
|
30
|
+
Given %{I am on the sign out page}
|
31
|
+
Then %{I should be on the homepage page}
|
32
|
+
#And %{I should see "Sign out successful"}
|
33
|
+
end
|