Step Definitions & Transforms
1 2 3 4 5 |
When(/I am "(.+?)"$/) do |user_name| model = find_model('User') @current_user = model.where(name: user_name).first! end |
When
I am "Dennis Ritchie"
features/enterprise_authorization.feature:66
features/enterprise_authorization.feature:81
features/enterprise_authorization.feature:221
When
I am "Rob Pike"
features/enterprise_authorization.feature:69
features/enterprise_authorization.feature:92
features/enterprise_authorization.feature:227
When
I am "William Gates"
features/enterprise_authorization.feature:72
features/enterprise_authorization.feature:110
features/enterprise_authorization.feature:236
When
I am "Steve Jobs"
features/enterprise_authorization.feature:75
features/enterprise_authorization.feature:117
features/enterprise_authorization.feature:245
When
I am "Tim Berners-Lee"
features/enterprise_authorization.feature:101
6 7 8 9 10 11 12 13 14 15 16 |
Then(/I should receive a DSL error (.+?) saying/) do |error_class, error_contents| error_class = error_class.constantize model = find_model(@model_name) if @model_name error_contents += '.+(feature)' unless error_contents.include?('\(feature\)') expect { eval_dsl(@definition, model) }.to \ raise_error(error_class). (/#{error_contents}/m) end |
Then
I should receive a DSL error SyntaxError saying
features/authorization_parse_error.feature:11
Then
I should receive a DSL error Eaco::Error saying
features/authorization_parse_error.feature:21
features/authorization_parse_error.feature:38
features/authorization_parse_error.feature:52
features/authorization_parse_error.feature:66
features/authorization_parse_error.feature:80
features/authorization_parse_error.feature:93
features/authorization_parse_error.feature:107
features/authorization_parse_error.feature:117
features/authorization_parse_error.feature:127
features/authorization_parse_error.feature:143
features/authorization_parse_error.feature:154
1 2 3 4 |
When(/I have a wrong authorization definition (?:on model (.+?))? *such as/) do |model_name, definition| @model_name = model_name @definition = definition end |
When
I have a wrong authorization definition such as
features/authorization_parse_error.feature:7
features/authorization_parse_error.feature:17
features/authorization_parse_error.feature:27
features/authorization_parse_error.feature:86
features/authorization_parse_error.feature:99
features/authorization_parse_error.feature:133
When
I have a wrong authorization definition on model User such as
features/authorization_parse_error.feature:44
features/authorization_parse_error.feature:58
When
I have a wrong authorization definition on model Document such as
features/authorization_parse_error.feature:72
features/authorization_parse_error.feature:123
features/authorization_parse_error.feature:150
When
I have a wrong authorization definition on model Department such as
features/authorization_parse_error.feature:113
14 15 16 17 18 19 |
Then(/I can not (\w+) the Documents? "(.+?)" *(?:being a (\w+))?$/) do |, document_names, role| check_documents document_names do |document| expect(@current_user.cannot?(, document)).to eq(true) expect(document.role_of(@current_user)).to eq(role ? role.intern : nil) end end |
But
I can not write the Document "For BAR and ICT" being a reader
features/enterprise_authorization.feature:68
features/enterprise_authorization.feature:71
features/enterprise_authorization.feature:74
Then
I can not read the Document "For BAR and ICT"
features/enterprise_authorization.feature:76
And
I can not write the Document "For BAR and ICT"
features/enterprise_authorization.feature:77
But
I can not read the Document "Tim's Web Project"
features/enterprise_authorization.feature:85
But
I can not write the Document "Tim's Web Project" being a reader
features/enterprise_authorization.feature:94
Then
I can not read the Document "ICT Status Report, ICT Budget Report"
features/enterprise_authorization.feature:102
Then
I can not read the Documents "ICT Status Report, ICT Budget Report, Tim's Web Project"
features/enterprise_authorization.feature:111
features/enterprise_authorization.feature:118
And
I can not write the Document "Cafeteria Menu" being a reader
features/enterprise_authorization.feature:119
7 8 9 10 11 12 |
Then(/I can (\w+) the Documents? "(.+?)" being a (\w+)$/) do |, document_names, role| check_documents document_names do |document| expect(@current_user.can?(, document)).to eq(true) expect(document.role_of(@current_user)).to eq(role.intern) end end |
Then
I can read the Document "For BAR and ICT" being a reader
features/enterprise_authorization.feature:67
features/enterprise_authorization.feature:70
features/enterprise_authorization.feature:73
Then
I can read the Document "ICT Status Report" being a writer
features/enterprise_authorization.feature:82
And
I can write the Document "ICT Budget Report" being a writer
features/enterprise_authorization.feature:83
And
I can read the Document "Cafeteria Menu" being a reader
features/enterprise_authorization.feature:84
features/enterprise_authorization.feature:120
Then
I can read the Documents "ICT Status Report, Tim's Web Project" being a reader
features/enterprise_authorization.feature:93
And
I can read the Document "Tim's Web Project" being a writer
features/enterprise_authorization.feature:103
And
I can write the Document "Tim's Web Project" being a writer
features/enterprise_authorization.feature:104
But
I can write the Document "Cafeteria Menu" being a writer
features/enterprise_authorization.feature:112
5 6 7 |
When(/I have a confidential (\w+) named "([\w\s]+)"/) do |model_name, resource_name| register_resource model_name, resource_name end |
When
I have a confidential Document named "For BAR and ICT"
features/enterprise_authorization.feature:62
When
I have a confidential Document named "Supa Dupa Fly"
features/role_based_authorization.feature:34
When
I have a confidential Document named "Strategic Plan"
features/role_based_authorization.feature:43
And
I have a confidential Document named "For Tom"
features/role_based_authorization.feature:45
And
I have a confidential Document named "For no one"
features/role_based_authorization.feature:47
features/role_based_authorization.feature:55
And
I have a confidential Document named "For Bob"
features/role_based_authorization.feature:53
When
I have a confidential Document named "Foo Bar"
features/role_based_authorization.feature:60
11 12 13 14 15 16 17 18 19 20 21 22 |
When(/I invoke the Controller "(.+?)" action with query string "(.+?)"$/) do |action_name, query| @controller = @controller_class.new @action_name = action_name @controller.current_user = @current_user @controller.request = ActionDispatch::TestRequest.new('QUERY_STRING' => query).tap do |request| request.params.update('action' => @action_name) end @controller.response = ActionDispatch::TestResponse.new end |
And
I invoke the Controller "show" action with query string "name=ICT Status Report"
features/enterprise_authorization.feature:222
features/enterprise_authorization.feature:228
features/enterprise_authorization.feature:239
And
I invoke the Controller "edit" action with query string "name=ICT Status Report"
features/enterprise_authorization.feature:224
features/enterprise_authorization.feature:230
And
I invoke the Controller "edit" action with query string "name=Cafeteria Menu"
features/enterprise_authorization.feature:237
And
I invoke the Controller "show" action with query string "name=One More Thing"
features/enterprise_authorization.feature:246
21 22 23 24 25 26 |
When(/I ask for Documents I can access, I get/) do |table| model = find_model('Document') names = table.raw.flatten expect(model.accessible_by(@current_user).map(&:name)).to match_array(names) end |
71 72 73 74 75 76 77 |
Then(/its role on the Documents? "(.+?)" should be (\w+)/) do |document_names, role| role = role == 'nil' ? nil : role.intern check_documents document_names do |document| expect(document.role_of(@designator)).to eq(role) end end |
Then
its role on the Document "ICT Status Report" should be reader
features/enterprise_authorization.feature:180
And
its role on the Documents "Cafeteria Menu, ICT Budget Report, Tim's Web Project" should be nil
features/enterprise_authorization.feature:181
Then
its role on the Documents "ICT Status Report, ICT Budget Report" should be writer
features/enterprise_authorization.feature:183
And
its role on the Documents "Cafeteria Menu, Tim's Web Project" should be nil
features/enterprise_authorization.feature:184
13 14 15 16 17 18 19 |
When(/I grant (\w+) access to (\w+) "(.+?)" as a (\w+) in quality of (\w+)/) do |actor_name, resource_model, resource_name, role_name, designator| actor = fetch_actor(actor_name) resource = fetch_resource(resource_model, resource_name) resource.grant role_name, designator, actor resource.save! end |
And
I grant Bob access to Document "Supa Dupa Fly" as a reader in quality of user
features/role_based_authorization.feature:35
And
I grant Bob access to Document "Strategic Plan" as a reader in quality of user
features/role_based_authorization.feature:44
And
I grant Tom access to Document "For Tom" as a reader in quality of user
features/role_based_authorization.feature:46
And
I grant Bob access to Document "For Bob" as a reader in quality of user
features/role_based_authorization.feature:54
40 41 42 |
Then(/it should describe itself as "(.+?)"/) do |description| expect(@designator.describe).to eq(description) end |
Then
it should describe itself as "User 'Steve Jobs'"
features/enterprise_authorization.feature:126
Then
it should describe itself as "Director in ICT"
features/enterprise_authorization.feature:134
Then
it should describe itself as "ICT"
features/enterprise_authorization.feature:142
Then
it should describe itself as "Any authenticated user"
features/enterprise_authorization.feature:151
24 25 26 |
Then(/the Controller should not raise an error/) do expect { @controller.process @action_name }.to_not raise_error end |
Then
the Controller should not raise an error
features/enterprise_authorization.feature:223
features/enterprise_authorization.feature:225
features/enterprise_authorization.feature:229
features/enterprise_authorization.feature:238
54 55 56 57 58 |
Then(/it should resolve itself to/) do |table| names = table.raw.flatten expect(@designator.resolve.map(&:name)).to match_array(names) end |
50 51 52 |
Then(/it should have a label of "(.+?)"/) do |label| expect(@designator.label).to eq(label) end |
And
it should have a label of "User"
features/enterprise_authorization.feature:127
And
it should have a label of "Position"
features/enterprise_authorization.feature:135
And
it should have a label of "Department"
features/enterprise_authorization.feature:143
And
it should have a label of "Any user"
features/enterprise_authorization.feature:152
44 45 46 47 48 |
Then(/it should serialize to JSON as (.+?)$/) do |json| json = MultiJson.load(json).symbolize_keys expect(@designator.as_json).to eq(json) end |
And
it should serialize to JSON as {"label": "User 'Steve Jobs'", "value": "user:4"}
features/enterprise_authorization.feature:128
And
it should serialize to JSON as {"label": "Director in ICT", "value": "position:1"}
features/enterprise_authorization.feature:136
And
it should serialize to JSON as {"label": "ICT", "value": "department:ICT"}
features/enterprise_authorization.feature:144
And
it should serialize to JSON as {"label": "Any authenticated user", "value": "authenticated:Eaco::Cucumber::ActiveRecord::User"}
features/enterprise_authorization.feature:153
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Given(/I have the following (\w+) records/) do |model_name, table| model = find_model(model_name) table.hashes.each do |attributes| instance = model.new if attributes.key?('acl') attributes['acl'] = MultiJson.load(attributes['acl']) end instance.attributes = attributes instance.save! end end |
Given
I have the following User records
features/enterprise_authorization.feature:32
Given
I have the following Department records
features/enterprise_authorization.feature:40
Given
I have the following Position records
features/enterprise_authorization.feature:46
Given
I have the following Document records
features/enterprise_authorization.feature:54
22 23 24 25 26 27 28 29 30 31 32 |
Then(/(\w+) can see (?:only)? *"(.*?)" in the (\w+) authorized list/) do |actor_name, resource_names, resource_model| actor = fetch_actor(actor_name) resource_names = resource_names.split(/,\s*/) resources = resource_names.map {|name| fetch_resource(resource_model, name)} resource_model = find_model(resource_model) accessible = resource_model.accessible_by(actor) expect(accessible).to match_array(resources) end |
Then
Bob can see only "Strategic Plan" in the Document authorized list
features/role_based_authorization.feature:48
And
Tom can see only "For Tom" in the Document authorized list
features/role_based_authorization.feature:49
Then
Bob can see only "For Bob" in the Document authorized list
features/role_based_authorization.feature:56
But
Boss can see "For Bob, For no one" in the Document authorized list
features/role_based_authorization.feature:57
28 29 30 31 32 33 34 |
Then(/the Controller should raise an (.+?) error saying/) do |error_class, error_contents| error_class = error_class.constantize expect { @controller.process @action_name }.to \ raise_error(error_class). (/#{error_contents}/) end |
Then
the Controller should raise an Eaco::Forbidden error saying
features/enterprise_authorization.feature:231
features/enterprise_authorization.feature:240
Then
the Controller should raise an Eaco::Error error saying
features/enterprise_authorization.feature:247
28 29 30 |
When(/I make a Designator with "(\w+)" and "(.+?)"/) do |type, value| @designator = Eaco::Designator.make(type, value) end |
When
I make a Designator with "position" and "1"
features/enterprise_authorization.feature:133
features/enterprise_authorization.feature:182
When
I make a Designator with "authenticated" and "Eaco::Cucumber::ActiveRecord::User"
features/enterprise_authorization.feature:150
32 33 34 |
When(/I parse the Designator "(.+?)"/) do |text| @designator = Eaco::Designator.parse(text) end |
When
I parse the Designator "user:4"
features/enterprise_authorization.feature:125
When
I parse the Designator "department:ICT"
features/enterprise_authorization.feature:141
features/enterprise_authorization.feature:179
1 2 3 |
When(/I have a (\w+) resource defined as/) do |model_name, resource_definition| model_name, resource_definition end |
Given
I have a Document resource defined as
features/rails_integration.feature:5
features/enterprise_authorization.feature:17
features/role_based_authorization.feature:7
44 45 46 47 48 49 |
Then(/^(\w+) should not be able to (\w+) (\w+) "(.+?)"$/) do |actor_name, , resource_model, resource_name| actor = fetch_actor(actor_name) resource = fetch_resource(resource_model, resource_name) expect(actor.cannot?(, resource)).to be(true) end |
But
Bob should not be able to write Document "Supa Dupa Fly"
features/role_based_authorization.feature:37
And
Tom should not be able to read Document "Supa Dupa Fly"
features/role_based_authorization.feature:38
Then
Bob should not be able to read Document "Supa Dupa Fly"
features/role_based_authorization.feature:40
5 6 7 |
Given(/I have an (\w+) actor named "(.+?)"/) do |model_name, actor_name| register_actor model_name, actor_name end |
Given
I have an User actor named "Bob"
features/role_based_authorization.feature:30
And
I have an User actor named "Tom"
features/role_based_authorization.feature:31
1 2 3 |
Given(/I have an (\w+) actor defined as/) do |model_name, actor_definition| model_name, actor_definition end |
Given
I have an User actor defined as
features/enterprise_authorization.feature:6
features/role_based_authorization.feature:18
36 37 38 |
When(/I have a plain object as a Designator/) do @designator = Object.new end |
When
I have a plain object as a Designator
features/enterprise_authorization.feature:187
60 61 62 |
When(/I have the following designators/) do |table| @designators = table.raw.flatten end |
When
I have the following designators
features/enterprise_authorization.feature:162
64 65 66 67 68 69 |
Then(/they should resolve to/) do |table| resolved = Eaco::Designator.resolve(@designators) names = table.raw.flatten expect(resolved.map(&:name)).to match_array(names) end |
Then
they should resolve to
features/enterprise_authorization.feature:166
79 80 81 82 83 84 85 86 87 |
Then(/its role on the Documents? "(.+?)" should give an (.+?) error saying/) do |document_names, error_class, error_contents| error_class = error_class.constantize check_documents document_names do |document| expect { document.role_of(@designator) }.to \ raise_error(error_class). (/#{error_contents}/) end end |
Then
its role on the Document "ICT Status Report" should give an Eaco::Error error saying
features/enterprise_authorization.feature:188
89 90 91 92 93 |
When(/I ask the Document the list of roles and labels/) do model = find_model('Document') @roles_labels = model.roles_with_labels end |
When
I ask the Document the list of roles and labels
features/enterprise_authorization.feature:194
95 96 97 98 99 100 101 |
Then(/I should get the following roles and labels/) do |table| expected = table.raw.map do |role, label| [role.to_sym, label] end expect(@roles_labels.to_a).to match(expected) end |
Then
I should get the following roles and labels
features/enterprise_authorization.feature:195
1 2 3 4 5 6 7 8 9 |
When(/I have an authorized Controller defined as/) do |controller_code| require 'action_controller' require 'eaco/controller' @controller_class = Class.new(ActionController::Base) @controller_class.send(:attr_accessor, :current_user) @controller_class.instance_eval { include Eaco::Controller } @controller_class.class_eval controller_code end |
When
I have an authorized Controller defined as
features/enterprise_authorization.feature:200
9 10 11 12 13 14 15 16 17 18 19 20 |
Then(/I should be able to set an ACL on the (\w+)/) do |model_name| resource_model = find_model(model_name) instance = resource_model.new instance.acl = {"foo" => :bar} instance.save! instance = resource_model.find(instance.id) expect(instance.acl).to eq({"foo" => :bar}) expect(instance.acl).to be_a(resource_model.acl) end |
Then
I should be able to set an ACL on the Document
features/rails_integration.feature:11
43 44 45 46 47 48 49 |
Then(/I should receive a Resource error (.+?) saying/) do |error_class, error_contents| error_class = error_class.constantize expect { @resource.grant @role_name, @designator, @actor }.to \ raise_error(error_class). (/#{error_contents}/) end |
Then
I should receive a Resource error Eaco::Error saying
features/role_based_authorization.feature:62
When
/I grant (\w+) access to (\w+) "(.+?)" as an invalid role (\w+) in quality of (\w+)/
37 38 39 40 41 |
When(/I grant (\w+) access to (\w+) "(.+?)" as an invalid role (\w+) in quality of (\w+)/) do |actor_name, resource_model, resource_name, role_name, designator| @actor = fetch_actor(actor_name) @resource = fetch_resource(resource_model, resource_name) @role_name, @designator = role_name, designator end |
And
I grant Bob access to Document "Foo Bar" as an invalid role frupper in quality of zomg
features/role_based_authorization.feature:61
29 30 31 32 33 34 35 |
Then(/I should receive a Designator error (.+?) saying/) do |error_class, error_contents| error_class = error_class.constantize expect { Eaco::Designator.parse(@designator_text) }.to \ raise_error(error_class). (/#{error_contents}/) end |
Then
I should receive a Designator error Eaco::Error saying
features/enterprise_authorization.feature:173
25 26 27 |
When(/I parse the invalid Designator "(.+?)"/) do |text| @designator_text = text end |
When
I parse the invalid Designator "foo:on the rocks"
features/enterprise_authorization.feature:172
18 19 20 21 22 23 |
When(/I am using ActiveRecord (.+?)$/) do |version| version = version.sub(/\D/, '') # FIXME allow_any_instance_of(Eaco::Adapters::ActiveRecord::Compatibility).to \ receive(:active_record_version).and_return(version) end |
When
I am using ActiveRecord 3.0
features/authorization_parse_error.feature:149
37 38 39 40 41 42 |
Then(/^(\w+) should be able to (\w+) (\w+) "(.+?)"$/) do |actor_name, , resource_model, resource_name| actor = fetch_actor(actor_name) resource = fetch_resource(resource_model, resource_name) expect(actor.can?(, resource)).to be(true) end |
Then
Bob should be able to read Document "Supa Dupa Fly"
features/role_based_authorization.feature:36
29 30 31 32 33 34 35 |
When(/I revoke (\w+) access to (\w+) "(.+?)" in quality of (\w+)/) do |actor_name, resource_model, resource_name, designator| actor = fetch_actor(actor_name) resource = fetch_resource(resource_model, resource_name) resource.revoke designator, actor resource.save! end |
But
I revoke Bob access to Document "Supa Dupa Fly" in quality of user
features/role_based_authorization.feature:39
21 22 23 24 25 26 27 |
When(/I grant access to (\w+) "(.+?)" to the following designators as (\w+)/) do |resource_model, resource_name, role, table| resource = fetch_resource(resource_model, resource_name) designators = table.raw.flatten.map {|d| Eaco::Designator.parse(d) } resource.batch_grant role, designators resource.save! end |
And
I grant access to Document "For BAR and ICT" to the following designators as reader
features/enterprise_authorization.feature:63
9 10 11 |
Given(/I have an admin (\w+) actor named "(.+?)"/) do |model_name, actor_name| register_actor model_name, actor_name, admin: true end |
When
I have an admin User actor named "Boss"
features/role_based_authorization.feature:52
No undefined steps