hydra_attribute 0.4.2 → 0.5.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/.gitignore +2 -1
  2. data/.travis.yml +6 -5
  3. data/CHANGELOG.md +6 -0
  4. data/Gemfile +1 -1
  5. data/README.md +3 -3
  6. data/Rakefile +2 -7
  7. data/gemfiles/activerecord-3.2.gemfile +5 -0
  8. data/hydra_attribute.gemspec +6 -7
  9. data/lib/hydra_attribute.rb +17 -18
  10. data/lib/hydra_attribute/active_record.rb +34 -13
  11. data/lib/hydra_attribute/active_record/association_preloader.rb +47 -28
  12. data/lib/hydra_attribute/active_record/attribute_methods.rb +29 -140
  13. data/lib/hydra_attribute/active_record/mass_assignment_security.rb +39 -0
  14. data/lib/hydra_attribute/active_record/migration.rb +4 -4
  15. data/lib/hydra_attribute/active_record/relation.rb +6 -7
  16. data/lib/hydra_attribute/active_record/relation/query_methods.rb +28 -18
  17. data/lib/hydra_attribute/hydra_attribute.rb +12 -49
  18. data/lib/hydra_attribute/hydra_attribute_set.rb +67 -0
  19. data/lib/hydra_attribute/hydra_entity.rb +110 -0
  20. data/lib/hydra_attribute/hydra_entity_attribute_association.rb +155 -0
  21. data/lib/hydra_attribute/hydra_set.rb +24 -26
  22. data/lib/hydra_attribute/hydra_value.rb +210 -0
  23. data/lib/hydra_attribute/identity_map.rb +18 -0
  24. data/lib/hydra_attribute/middleware/identity_map.rb +15 -0
  25. data/lib/hydra_attribute/migrator.rb +24 -21
  26. data/lib/hydra_attribute/model.rb +47 -0
  27. data/lib/hydra_attribute/model/cacheable.rb +207 -0
  28. data/lib/hydra_attribute/model/dirty.rb +39 -0
  29. data/lib/hydra_attribute/model/has_many_through.rb +168 -0
  30. data/lib/hydra_attribute/model/identity_map.rb +59 -0
  31. data/lib/hydra_attribute/model/mediator.rb +89 -0
  32. data/lib/hydra_attribute/model/notifiable.rb +23 -0
  33. data/lib/hydra_attribute/model/persistence.rb +424 -0
  34. data/lib/hydra_attribute/model/validations.rb +40 -0
  35. data/lib/hydra_attribute/version.rb +1 -1
  36. data/spec/environments/mysql.rb +23 -0
  37. data/spec/environments/postgresql.rb +23 -0
  38. data/spec/environments/sqlite.rb +12 -0
  39. data/spec/fixtures/category.rb +8 -0
  40. data/spec/fixtures/product.rb +8 -0
  41. data/spec/fixtures/product_black_list.rb +13 -0
  42. data/spec/fixtures/product_white_list.rb +13 -0
  43. data/spec/hydra_attribute/active_record/attribute_methods_spec.rb +23 -28
  44. data/spec/hydra_attribute/active_record/mass_assignment_security_spec.rb +41 -0
  45. data/spec/hydra_attribute/active_record_spec.rb +577 -0
  46. data/spec/hydra_attribute/hydra_attribute_set_spec.rb +651 -0
  47. data/spec/hydra_attribute/hydra_attribute_spec.rb +208 -10
  48. data/spec/hydra_attribute/hydra_entity_attribute_association_spec.rb +216 -0
  49. data/spec/hydra_attribute/hydra_entity_spec.rb +71 -0
  50. data/spec/hydra_attribute/hydra_set_spec.rb +51 -10
  51. data/spec/hydra_attribute/hydra_value_spec.rb +286 -0
  52. data/spec/hydra_attribute/identity_map_spec.rb +47 -0
  53. data/spec/hydra_attribute/migrator_spec.rb +411 -0
  54. data/spec/hydra_attribute/model/cacheable_spec.rb +106 -0
  55. data/spec/hydra_attribute/model/has_many_through_spec.rb +132 -0
  56. data/spec/hydra_attribute/model/identity_map_spec.rb +39 -0
  57. data/spec/hydra_attribute/model/mediator_spec.rb +62 -0
  58. data/spec/hydra_attribute/model/persistence_spec.rb +550 -0
  59. data/spec/hydra_attribute/model_spec.rb +39 -0
  60. data/spec/hydra_attribute_spec.rb +36 -0
  61. data/spec/spec_helper.rb +10 -42
  62. metadata +76 -100
  63. data/Appraisals +0 -7
  64. data/cucumber.yml +0 -1
  65. data/features/entity/create.feature +0 -145
  66. data/features/entity/destroy.feature +0 -111
  67. data/features/entity/new.feature +0 -121
  68. data/features/entity/update.feature +0 -147
  69. data/features/hydra_attribute/create.feature +0 -30
  70. data/features/hydra_attribute/destroy.feature +0 -26
  71. data/features/hydra_attribute/update.feature +0 -36
  72. data/features/hydra_set/destroy.feature +0 -31
  73. data/features/migrations/create_and_drop.feature +0 -165
  74. data/features/migrations/migrate_and_rollback.feature +0 -211
  75. data/features/relation/query_methods/group.feature +0 -42
  76. data/features/relation/query_methods/order.feature +0 -67
  77. data/features/relation/query_methods/reorder.feature +0 -29
  78. data/features/relation/query_methods/reverse_order.feature +0 -29
  79. data/features/relation/query_methods/select.feature +0 -50
  80. data/features/relation/query_methods/where.feature +0 -115
  81. data/features/step_definitions/connections.rb +0 -65
  82. data/features/step_definitions/model_steps.rb +0 -136
  83. data/features/step_definitions/query_methods.rb +0 -48
  84. data/features/step_definitions/record_steps.rb +0 -93
  85. data/features/support/env.rb +0 -38
  86. data/features/support/world.rb +0 -61
  87. data/lib/hydra_attribute/active_record/association.rb +0 -113
  88. data/lib/hydra_attribute/active_record/reflection.rb +0 -16
  89. data/lib/hydra_attribute/association_builder.rb +0 -69
  90. data/lib/hydra_attribute/builder.rb +0 -37
  91. data/lib/hydra_attribute/entity_callbacks.rb +0 -26
  92. data/lib/hydra_attribute/hydra_attribute_methods.rb +0 -226
  93. data/lib/hydra_attribute/hydra_methods.rb +0 -528
  94. data/lib/hydra_attribute/hydra_set_methods.rb +0 -95
  95. data/lib/hydra_attribute/hydra_value_methods.rb +0 -21
  96. data/lib/hydra_attribute/memoizable.rb +0 -37
  97. data/spec/hydra_attribute/active_record/relation/query_methods_spec.rb +0 -31
  98. data/spec/hydra_attribute/hydra_attribute_methods_spec.rb +0 -458
  99. data/spec/hydra_attribute/hydra_methods_spec.rb +0 -456
  100. data/spec/hydra_attribute/hydra_set_methods_spec.rb +0 -203
  101. data/spec/hydra_attribute/memoizable_spec.rb +0 -95
@@ -1,67 +0,0 @@
1
- Feature: order conditions by hydra attributes
2
- When order records by hydra attribute
3
- Then correct table should be joined and order by value should be added
4
-
5
- When correct table is already joined
6
- Then only order condition should be added
7
-
8
- When order by several attributes
9
- Then order all of them by ascending
10
-
11
- Background: create hydra attributes
12
- Given create hydra attributes for "Product" with role "admin" as "hashes":
13
- | name | backend_type | white_list |
14
- | code | integer | [bool:t] |
15
- | state | integer | [bool:t] |
16
- | title | string | [bool:t] |
17
-
18
- Scenario Outline: order by one field
19
- Given create "Product" model with attributes as "hashes":
20
- | name | code | state |
21
- | c | 1 | 1 |
22
- | b | 2 | 2 |
23
- | a | 3 | 3 |
24
- When order "Product" records by "<attributes>"
25
- Then "first" record should have "<first identifier>"
26
- And "last" record should have "<last identifier>"
27
-
28
- Scenarios: order conditions
29
- | attributes | first identifier | last identifier |
30
- | state=asc | code=[int:1] | code=[int:3] |
31
- | state=desc | code=[int:3] | code=[int:1] |
32
- | name=asc | code=[int:3] | code=[int:1] |
33
- | name=desc | code=[int:1] | code=[int:3] |
34
-
35
- Scenario Outline: order by several attributes
36
- Given create "Product" model with attributes as "hashes":
37
- | name | code | state | title |
38
- | c | 1 | 1 | b |
39
- | b | 2 | 2 | a |
40
- | a | 3 | 3 | c |
41
- When order "Product" records by "<attributes>"
42
- Then "first" record should have "<first identifier>"
43
- And "last" record should have "<last identifier>"
44
-
45
- Scenarios: order conditions
46
- | attributes | first identifier | last identifier |
47
- | name state | code=[int:3] | code=[int:1] |
48
- | state title | code=[int:1] | code=[int:3] |
49
- | title state | code=[int:2] | code=[int:3] |
50
-
51
- Scenario Outline: order by filtered attribute
52
- Given create "Product" model with attributes as "hashes":
53
- | code | state | title |
54
- | 1 | 1 | |
55
- | 2 | | |
56
- | 3 | 1 | a |
57
- When filter "Product" records by "<filter attribute>"
58
- And order records by "<order attributes>"
59
- Then total records should be "<count>"
60
- And "first" record should have "<first identifier>"
61
- And "last" record should have "<last identifier>"
62
-
63
- Scenarios: order conditions
64
- | filter attribute | order attributes | count | first identifier | last identifier |
65
- | state=[int:1] | state code | 2 | code=[int:1] | code=[int:3] |
66
- | state=[nil:] | state code | 1 | code=[int:2] | code=[int:2] |
67
- | title=[nil:] | title code | 2 | code=[int:1] | code=[int:2] |
@@ -1,29 +0,0 @@
1
- Feature: reorder by hydra attributes
2
- When reorder relation object with new hydra attributes
3
- Then old order hydra attributes should be removed
4
- And new hydra attributes should be added to order list
5
-
6
- Background: create hydra attributes
7
- Given create hydra attributes for "Product" with role "admin" as "hashes":
8
- | name | backend_type | white_list |
9
- | code | integer | [bool:t] |
10
- | state | integer | [bool:t] |
11
- | title | string | [bool:t] |
12
-
13
- Scenario Outline: reorder
14
- Given create "Product" model with attributes as "hashes":
15
- | code | name | title |
16
- | 1 | a | c |
17
- | 2 | b | b |
18
- | 3 | c | a |
19
- When order "Product" records by "<order>"
20
- And reorder records by "<reorder>"
21
- Then total records should be "<count>"
22
- And "first" record should have "<first identifier>"
23
- And "last" record should have "<last identifier>"
24
-
25
- Scenarios: order conditions
26
- | order | reorder | count | first identifier | last identifier |
27
- | title | name title | 3 | code=[int:1] | code=[int:3] |
28
- | name | title name | 3 | code=[int:3] | code=[int:1] |
29
- | code | title | 3 | code=[int:3] | code=[int:1] |
@@ -1,29 +0,0 @@
1
- Feature: reverse order relation object
2
- When reverse order by hydra attribute
3
- Then relation object should reverse order of hydra attribute. ASC to DESC and vise versa
4
-
5
- Background: create hydra attributes
6
- Given create hydra attributes for "Product" with role "admin" as "hashes":
7
- | name | backend_type | white_list |
8
- | code | integer | [bool:t] |
9
- | state | integer | [bool:t] |
10
- | title | string | [bool:t] |
11
-
12
- Scenario Outline: reverse order
13
- Given create "Product" model with attributes as "hashes":
14
- | code | state | title |
15
- | 1 | 3 | a |
16
- | 2 | 2 | b |
17
- | 3 | 1 | c |
18
- When order "Product" records by "<order>"
19
- And reverse order records
20
- Then total records should be "3"
21
- And "first" record should have "<first>"
22
- And "last" record should have "<last>"
23
-
24
- Scenarios: conditions
25
- | order | first | last |
26
- | code | code=[int:3] | code=[int:1] |
27
- | state | code=[int:1] | code=[int:3] |
28
- | title | code=[int:3] | code=[int:1] |
29
-
@@ -1,50 +0,0 @@
1
- Feature: select concrete attributes
2
- When select concrete attribute
3
- Then model should response only to these attributes
4
-
5
- Background: create hydra attributes
6
- Given create hydra attributes for "Product" with role "admin" as "hashes":
7
- | name | backend_type | white_list |
8
- | code | integer | [bool:t] |
9
- | price | float | [bool:t] |
10
- | title | string | [bool:t] |
11
- | note | text | [bool:t] |
12
- | active | boolean | [bool:t] |
13
- | schedule | datetime | [bool:t] |
14
- And create "Product" model with attributes as "hashes":
15
- | name | code | price | title | note | active | schedule |
16
- | a | 1 | 4 | q | z | 1 | 2012-06-01 |
17
- | b | 2 | 5 | w | x | 0 | 2012-06-02 |
18
- | c | 3 | 6 | | c | 1 | 2012-06-03 |
19
- | d | | 7 | | v | 0 | 2012-06-04 |
20
-
21
- Scenario Outline: select concrete attributes
22
- When "Product" select only the following columns "<selected columns>"
23
- Then records should have only the following "<expected columns>" names
24
- And records should raise "ActiveModel::MissingAttributeError" when call the following "<methods>"
25
- And total records should be "4"
26
-
27
- Scenarios: select attributes
28
- | selected columns | expected columns | methods |
29
- | name | id hydra_set_id name | code price title note active schedule |
30
- | name code | id hydra_set_id name code | price title note active schedule |
31
- | name code price | id hydra_set_id name code price | title note active schedule |
32
- | code price title | id hydra_set_id code price title | name note active schedule |
33
- | title note active | id hydra_set_id title note active | name code price schedule |
34
- | schedule | id hydra_set_id schedule | name code price title note active |
35
- | id schedule | id hydra_set_id schedule | name code price title note active |
36
-
37
- Scenario Outline: filter collection and select concrete attributes
38
- When "Product" select only the following columns "<selected columns>"
39
- And filter records by "<filter attributes>"
40
- Then records should have only the following "<expected columns>" names
41
- And records should raise "ActiveModel::MissingAttributeError" when call the following "<methods>"
42
- And total records should be "<total>"
43
-
44
- Scenarios: filter and select attributes
45
- | selected columns | expected columns | filter attributes | methods | total |
46
- | name code | id hydra_set_id name code | name=a | price title note active schedule | 1 |
47
- | code | id hydra_set_id code | code=[int:1] | name price title note active schedule | 1 |
48
- | name code | id hydra_set_id name code | code=[int:1] | price title note active schedule | 1 |
49
- | code title | id hydra_set_id code title | title=[nil:] | name price note active schedule | 2 |
50
- | code note | id hydra_set_id code note | title=[nil:] | name price title active schedule | 2 |
@@ -1,115 +0,0 @@
1
- Feature: hydra attribute where conditions
2
- When filter by hydra attribute and this value is not nil
3
- Then records with this attribute should be selected
4
-
5
- When filter by hydra attribute and this value is nil
6
- Then records with nil and blank value should be selected
7
-
8
- Background: create hydra attributes
9
- Given create hydra attributes for "Product" with role "admin" as "hashes":
10
- | name | backend_type | white_list |
11
- | code | string | [bool:t] |
12
- | summary | string | [bool:t] |
13
- | title | string | [bool:t] |
14
- | price | float | [bool:t] |
15
- | active | boolean | [bool:t] |
16
- | state | integer | [bool:t] |
17
-
18
- Scenario: filter by one hydra attribute
19
- Given create "Product" model with attributes as "hashes":
20
- | code | price |
21
- | 1 | 2.75 |
22
- | 2 | 2.75 |
23
- | 3 | 2.76 |
24
- | 4 | |
25
- When filter "Product" by:
26
- | field | value |
27
- | price | 2.75 |
28
- Then total records should be "2"
29
- And records should have the following attributes:
30
- | field | value |
31
- | code | 1 |
32
- | code | 2 |
33
-
34
- Scenario: filter by one hydra attribute with nil value
35
- Given create "Product" model with attributes as "hashes":
36
- | code | price |
37
- | 1 | |
38
- | 2 | 0 |
39
- | 3 | |
40
- When filter "Product" by:
41
- | field | value |
42
- | price | [nil:] |
43
- Then total records should be "2"
44
- And records should have the following attributes:
45
- | field | value |
46
- | code | 1 |
47
- | code | 3 |
48
-
49
- Scenario: filter by several fields including both the hydra and general attributes
50
- Given create "Product" model with attributes as "hashes":
51
- | name | code | title | price | active | state | summary |
52
- | toy | 1 | story | 2.40 | 1 | | |
53
- | toy | 2 | story | 2.45 | 1 | | |
54
- | toy | 3 | story | 2.45 | 1 | | |
55
- | toy | 4 | | 2.45 | 0 | | |
56
- | | 5 | | 2.45 | 1 | | |
57
- | toy | 6 | | 2.46 | 1 | | |
58
- When filter "Product" by:
59
- | field | value |
60
- | name | toy |
61
- | title | story |
62
- | summary | [nil:] |
63
- | price | [float:2.45] |
64
- | active | [bool:t] |
65
- | state | [nil:] |
66
- Then total records should be "2"
67
- And records should have the following attributes:
68
- | field | value |
69
- | code | 2 |
70
- | code | 3 |
71
-
72
- Scenario: select entity if it has attribute in attribute set
73
- Given create hydra set "Default" for "Product"
74
- And set hydra attributes "[array:code,title]" to hydra set "Default" for entity "Product"
75
- And create "Product" models with attributes as "hashes":
76
- | hydra_set_id | code | title |
77
- | | abc1 | book |
78
- | [eval:Product.hydra_set('Default').id] | abc2 | book |
79
- When filter "Product" by:
80
- | field | value |
81
- | title | book |
82
- Then total records should be "2"
83
- And records should have the following attributes:
84
- | field | value |
85
- | code | abc1 |
86
- | code | abc2 |
87
-
88
- Scenario: when filter attribute by nil value then entities without this attribute in attribute set should not be selected
89
- Given create hydra set "Default" for "Product"
90
- And create "Product" model
91
- And create "Product" model with attributes as "rows_hash":
92
- | hydra_set_id | [eval:Product.hydra_set('Default').id] |
93
- When filter "Product" by:
94
- | field | value |
95
- | code | [nil:] |
96
- Then total records should be "1"
97
- And records should have the following attributes:
98
- | field | value |
99
- | hydra_set_id | [nil:] |
100
-
101
- Scenario: when filter attribute by value then entities which don't have this attribute in attribute set any more should not be selected
102
- Given create hydra set "Default" for "Product"
103
- And add hydra attribute "code" to hydra set "Default" for entity "Product"
104
- And create "Product" models with attributes as "hashes":
105
- | hydra_set_id | code |
106
- | | abc |
107
- | [eval:Product.hydra_set('Default').id] | abc |
108
- And set hydra attributes "title" to hydra set "Default" for entity "Product"
109
- When filter "Product" by:
110
- | field | value |
111
- | code | abc |
112
- Then total records should be "1"
113
- And records should have the following attributes:
114
- | field | value |
115
- | hydra_set_id | [nil:] |
@@ -1,65 +0,0 @@
1
- Given /^create connection$/ do
2
- spec = ActiveRecord::Base::ConnectionSpecification.new({database: ':memory:', adapter: 'sqlite3'}, 'sqlite3_connection')
3
- @connection = ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec).connection
4
- end
5
-
6
- Given /^(create|drop|migrate|rollback)(?:\sto|\sfrom)? hydra entity "([^"]+)"$/ do |method, table|
7
- HydraAttribute::Migrator.send(method, @connection, table)
8
- end
9
-
10
- Given /^create table "([^"]+)"$/ do |table|
11
- @connection.create_table(table)
12
- end
13
-
14
- Then /^should have the following (\d+) tables?:$/ do |count, table|
15
- @connection.should have(count.to_i).tables
16
-
17
- table.rows.flatten.each do |name|
18
- @connection.tables.should include(name)
19
- end
20
- end
21
-
22
- Then /^should not have any tables$/ do
23
- @connection.should have(0).tables
24
- end
25
-
26
- Then /^table "([^"]+)" should have the following (columns|indexes):$/ do |table_name, method, table|
27
- connection_params = @connection.send(method, table_name).sort_by(&:name)
28
- checked_params = table.hashes.map { |hash| type_cast_hash(hash) }.sort_by { |param| param['name'] }
29
-
30
- unless connection_params.length == checked_params.length
31
- raise %(Table "#{table_name}" has "#{connection_params.length}" #{method} but in our test "#{checked_params.length}". Diff: is "#{connection_params.map(&:name)}" but should be "#{checked_params.map { |h| h['name'] }}")
32
- end
33
-
34
- connection_params.zip(checked_params).each do |(real_params, params)|
35
- params.keys.each do |name|
36
- params[name].should == real_params.send(name)
37
- end
38
- end
39
- end
40
-
41
- Then /^table "([^"]+)" should have (\d+) records?$/ do |table_name, count|
42
- result = ActiveRecord::Base.connection.select_one("SELECT COUNT(*) AS count FROM #{table_name}")
43
- result['count'].should == count.to_i
44
- end
45
-
46
- Then /^table "([^"]+)" should have (\d+) records?:$/ do |table_name, count, table|
47
- step %(table "#{table_name}" should have #{count} records)
48
-
49
- table.hashes.each do |hash|
50
- table = Arel::Table.new(table_name, ActiveRecord::Base)
51
- select = Arel.sql('COUNT(*)').as('count')
52
- where = hash.map { |name, value| table[name].eq(type_cast_value(value)) }.inject(:and)
53
-
54
- result = ActiveRecord::Base.connection.select_one(table.project(select).where(where))
55
- unless result['count']
56
- raise %(Query "#{table.project(select).where(where).to_sql}" return nil)
57
- end
58
-
59
- unless result['count'] == 1
60
- raise %(Query "#{table.project(select).where(where).to_sql}" return "#{result['count']}")
61
- end
62
- result['count'].should be(1)
63
- end
64
- end
65
-
@@ -1,136 +0,0 @@
1
- Given /^redefine "([^"]+)" class to use hydra attributes$/ do |klass|
2
- redefine_hydra_entity(klass)
3
- end
4
-
5
- Given /^create "([^"]+)" model$/ do |klass|
6
- klass.constantize.create!
7
- end
8
-
9
- Given /^build "([^"]+)" model$/ do |klass|
10
- @model = klass.constantize.new
11
- end
12
-
13
- Given /^build "([^"]+)" model:$/ do |klass, table|
14
- @model = klass.constantize.new(type_cast_hash(table.rows_hash))
15
- end
16
-
17
- When /^set "([^"]+)" to "([^"]+)"$/ do |attribute, value|
18
- @model.send("#{attribute}=", type_cast_value(value))
19
- end
20
-
21
- When /^(save|destroy) model$/ do |method|
22
- @model.send(method)
23
- end
24
-
25
- When /^find "([^"]+)" model by attribute "([^"]+)" and value "([^"]+)"$/ do |class_name, attribute, value|
26
- @model = class_name.constantize.send("find_by_#{attribute}", type_cast_value(value))
27
- end
28
-
29
- When /^find (first|last) "([^"]+)" model$/ do |method, class_name|
30
- @model = class_name.constantize.send(method)
31
- end
32
-
33
- When /^reload model$/ do
34
- @model.reload
35
- end
36
-
37
- Given /^create "([^"]+)" model with attributes as "([^"]+):"$/ do |klass, format, table|
38
- Array.wrap(table.send(format)).each do |hash|
39
- klass.constantize.create!(type_cast_hash(hash))
40
- end
41
- end
42
-
43
- Given /^create hydra attributes for "([^"]+)" with role "([^"]+)" as "([^"]+)":$/ do |klass, role, format, table|
44
- Array.wrap(table.send(format)).each do |hash|
45
- klass.constantize.hydra_attributes.create!(type_cast_hash(hash), as: role.to_sym)
46
- end
47
- end
48
-
49
- Given /^create hydra sets for "([^"]+)" as "([^"]+)":$/ do |klass, format, table|
50
- Array.wrap(table.send(format)).each do |hash|
51
- step %(create hydra set "#{hash['name']}" for "#{klass}")
52
- end
53
- end
54
-
55
- Given /^create hydra set "([^"]+)" for "([^"]+)"$/ do |hydra_set_name, klass|
56
- klass.constantize.hydra_sets.create!(name: type_cast_value(hydra_set_name))
57
- end
58
-
59
- Given /^add "([^"]+)" hydra attributes to hydra set:$/ do |klass, table|
60
- klass = klass.constantize
61
-
62
- Array.wrap(table.hashes).each do |hash|
63
- Array.wrap(type_cast_value(hash['hydra set name'])).each do |set|
64
- klass.hydra_sets.find_by_name(set).hydra_attributes << klass.hydra_attributes.find_by_name(type_cast_value(hash['hydra attribute name']))
65
- end
66
- end
67
- end
68
-
69
- Given /^add hydra attribute "([^"]+)" to hydra set "([^"]+)" for entity "([^"]+)"$/ do |hydra_attribute, hydra_set, entity_class|
70
- entity = entity_class.constantize
71
- entity.hydra_set(type_cast_value(hydra_set)).hydra_attributes << entity.hydra_attribute(type_cast_value(hydra_attribute))
72
- end
73
-
74
- Given /^set hydra attributes? "([^"]+)" to hydra set "([^"]+)" for entity "([^"]+)"$/ do |hydra_attributes, hydra_set, entity_class|
75
- entity = entity_class.constantize
76
- hydra_set = entity.hydra_set(type_cast_value(hydra_set))
77
-
78
- hydra_attributes = Array(type_cast_value(hydra_attributes)).map { |attr| entity.hydra_attribute(attr) }
79
- hydra_set.hydra_attributes = hydra_attributes
80
- end
81
-
82
- Given /^(load and )?(save|create|update(?: all| attributes)?|destroy(?: all)?|delete(?: all)?)(?: for)? "([^"]+)" models? with attributes as "([^"]+)":$/ do |load, action, klass, format, table|
83
- action = action.gsub(' ', '_')
84
- klass = klass.constantize
85
- models = load.present? ? klass.all : [klass]
86
-
87
- Array.wrap(table.send(format)).each do |hash|
88
- models.each do |model|
89
- model.send(action, type_cast_hash(hash))
90
- end
91
- end
92
- end
93
-
94
- Then /^model (should(?:\snot)?) respond to "([^"]+)"$/ do |method, attributes|
95
- method = method.gsub(/\s+/, '_')
96
- attributes.split.each do |attribute|
97
- @model.send(method, respond_to(attribute))
98
- end
99
- end
100
-
101
- Then /^model attributes (should(?:\snot)?) include "([^"]+)"$/ do |method, attributes|
102
- method = method.gsub(/\s+/, '_')
103
- attributes.split.each do |attribute|
104
- @model.attributes.keys.send(method, include(attribute))
105
- end
106
- end
107
-
108
- Then /^model attributes (should(?:\snot)?) match "([^"]+)"$/ do |match, attribute|
109
- @model.attributes.keys.send(match) =~ Array(type_cast_value(attribute))
110
- end
111
-
112
- Then /^model "([^"]+)" (should(?:\snot)?) respond to "([^"]+)"$/ do |klass, method, attributes|
113
- @model = klass.constantize.new
114
- step %(model #{method} respond to "#{attributes}")
115
- end
116
-
117
- Then /^error "([^"]+)" (should(?:\snot)?) be risen when methods? "([^"]+)" (?:is|are) called$/ do |error_class, expect, methods|
118
- Array.wrap(methods.split).each do |method|
119
- lambda { @model.send(method) }.send(expect.gsub(/\s+/, '_'), raise_error(error_class.constantize))
120
- end
121
- end
122
-
123
- Then /^(last|first) created "([^"]+)" (should|should not) have the following attributes:$/ do |position, klass, match, table|
124
- table.rows_hash.each do |attribute, value|
125
- step %(#{position} created "#{klass}" #{match} have attribute "#{attribute}" with value "#{value}")
126
- end
127
- end
128
-
129
- Then /^(last|first) created "([^"]+)" (should|should not) have attribute "([^"]+)" with value "([^"]+)"$/ do |position, klass, match, attribute, value|
130
- klass.constantize.send(position).send(attribute).send(match) == type_cast_value(value)
131
- end
132
-
133
- Then /^class "([^"]+)" (should(?:\snot)?) have "([^"]+)" in white list$/ do |klass, accept, attribute|
134
- method = accept.sub(' ', '_')
135
- klass.constantize.accessible_attributes.send(method, include(attribute))
136
- end