Step Definitions & Transforms
Then /I should receive a DSL error (.+?) saying/
Rubular [Collapse]
features/step_definitions/error_steps.rb:6
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).
    with_message(/#{error_contents}/m)
end
When /I have a wrong authorization definition (?:on model (.+?))? *such as/
Rubular [Collapse]
features/step_definitions/error_steps.rb:1
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
Then /I can not (\w+) the Documents? "(.+?)" *(?:being a (\w+))?$/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:14
14
15
16
17
18
19
Then(/I can not (\w+) the Documents? "(.+?)" *(?:being a (\w+))?$/) do |permission, document_names, role|
  check_documents document_names do |document|
    expect(@current_user.cannot?(permission, document)).to eq(true)
    expect(document.role_of(@current_user)).to eq(role ? role.intern : nil)
  end
end
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
Then /I can (\w+) the Documents? "(.+?)" being a (\w+)$/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:7
7
8
9
10
11
12
Then(/I can (\w+) the Documents? "(.+?)" being a (\w+)$/) do |permission, document_names, role|
  check_documents document_names do |document|
    expect(@current_user.can?(permission, document)).to eq(true)
    expect(document.role_of(@current_user)).to eq(role.intern)
  end
end
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
When /I have a confidential (\w+) named "([\w\s]+)"/
Rubular [Collapse]
features/step_definitions/resource_steps.rb:5
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 Bob"
features/role_based_authorization.feature:53
When I have a confidential Document named "Foo Bar"
features/role_based_authorization.feature:60
When /I invoke the Controller "(.+?)" action with query string "(.+?)"$/
Rubular [Collapse]
features/step_definitions/controller_steps.rb:11
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 "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
When /I ask for Documents I can access, I get/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:21
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
Then /its role on the Documents? "(.+?)" should be (\w+)/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:71
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
When /I grant (\w+) access to (\w+) "(.+?)" as a (\w+) in quality of (\w+)/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:13
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
Then /it should describe itself as "(.+?)"/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:40
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
Then /the Controller should not raise an error/
Rubular [Collapse]
features/step_definitions/controller_steps.rb:24
24
25
26
Then(/the Controller should not raise an error/) do
  expect { @controller.process @action_name }.to_not raise_error
end
Then /it should resolve itself to/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:54
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
Then /it should have a label of "(.+?)"/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:50
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
Then /it should serialize to JSON as (.+?)$/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:44
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
Given /I have the following (\w+) records/
Rubular [Collapse]
features/step_definitions/fixture_steps.rb:1
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
Then /(\w+) can see (?:only)? *"(.*?)" in the (\w+) authorized list/
Rubular [Collapse]
features/step_definitions/resource_steps.rb:22
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
Then /the Controller should raise an (.+?) error saying/
Rubular [Collapse]
features/step_definitions/controller_steps.rb:28
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).
    with_message(/#{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
When /I make a Designator with "(\w+)" and "(.+?)"/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:28
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 "authenticated" and "Eaco::Cucumber::ActiveRecord::User"
features/enterprise_authorization.feature:150
When /I parse the Designator "(.+?)"/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:32
32
33
34
When(/I parse the Designator "(.+?)"/) do |text|
  @designator = Eaco::Designator.parse(text)
end
When /I have a (\w+) resource defined as/
Rubular [Collapse]
features/step_definitions/resource_steps.rb:1
1
2
3
When(/I have a (\w+) resource defined as/) do |model_name, resource_definition|
  authorize_model model_name, resource_definition
end
Then /^(\w+) should not be able to (\w+) (\w+) "(.+?)"$/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:44
44
45
46
47
48
49
Then(/^(\w+) should not be able to (\w+) (\w+) "(.+?)"$/) do |actor_name, permission_name, resource_model, resource_name|
  actor = fetch_actor(actor_name)
  resource = fetch_resource(resource_model, resource_name)

  expect(actor.cannot?(permission_name, 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
Given /I have an (\w+) actor named "(.+?)"/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:5
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
Given /I have an (\w+) actor defined as/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:1
1
2
3
Given(/I have an (\w+) actor defined as/) do |model_name, actor_definition|
  authorize_model model_name, actor_definition
end
When /I have a plain object as a Designator/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:36
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
When /I have the following designators/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:60
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
Then /they should resolve to/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:64
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
Then /its role on the Documents? "(.+?)" should give an (.+?) error saying/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:79
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).
      with_message(/#{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
When /I ask the Document the list of roles and labels/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:89
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
Then /I should get the following roles and labels/
Rubular [Collapse]
features/step_definitions/enterprise_steps.rb:95
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
When /I have an authorized Controller defined as/
Rubular [Collapse]
features/step_definitions/controller_steps.rb:1
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
Then /I should be able to set an ACL on the (\w+)/
Rubular [Collapse]
features/step_definitions/resource_steps.rb:9
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
Then /I should receive a Resource error (.+?) saying/
Rubular [Collapse]
features/step_definitions/error_steps.rb:43
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).
    with_message(/#{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+)/
Rubular [Collapse]
features/step_definitions/error_steps.rb:37
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
Then /I should receive a Designator error (.+?) saying/
Rubular [Collapse]
features/step_definitions/error_steps.rb:29
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).
    with_message(/#{error_contents}/)
end
Then I should receive a Designator error Eaco::Error saying
features/enterprise_authorization.feature:173
When /I parse the invalid Designator "(.+?)"/
Rubular [Collapse]
features/step_definitions/error_steps.rb:25
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
When /I am using ActiveRecord (.+?)$/
Rubular [Collapse]
features/step_definitions/error_steps.rb:18
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
Then /^(\w+) should be able to (\w+) (\w+) "(.+?)"$/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:37
37
38
39
40
41
42
Then(/^(\w+) should be able to (\w+) (\w+) "(.+?)"$/) do |actor_name, permission_name, resource_model, resource_name|
  actor = fetch_actor(actor_name)
  resource = fetch_resource(resource_model, resource_name)

  expect(actor.can?(permission_name, resource)).to be(true)
end
Then Bob should be able to read Document "Supa Dupa Fly"
features/role_based_authorization.feature:36
When /I revoke (\w+) access to (\w+) "(.+?)" in quality of (\w+)/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:29
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
When /I grant access to (\w+) "(.+?)" to the following designators as (\w+)/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:21
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
Given /I have an admin (\w+) actor named "(.+?)"/
Rubular [Collapse]
features/step_definitions/actor_steps.rb:9
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