hydra_attribute 0.3.2 → 0.4.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/CHANGELOG.md +1 -1
  2. data/README.md +7 -0
  3. data/features/entity/create.feature +128 -0
  4. data/features/entity/destroy.feature +111 -0
  5. data/features/entity/new.feature +121 -0
  6. data/features/entity/update.feature +147 -0
  7. data/features/{attributes → hydra_attribute}/create.feature +7 -7
  8. data/features/{attributes → hydra_attribute}/destroy.feature +2 -4
  9. data/features/{attributes → hydra_attribute}/update.feature +10 -10
  10. data/features/hydra_set/destroy.feature +31 -0
  11. data/features/migrations/create_and_drop.feature +165 -0
  12. data/features/migrations/migrate_and_rollback.feature +211 -0
  13. data/features/relation/query_methods/group.feature +42 -0
  14. data/features/relation/query_methods/order.feature +67 -0
  15. data/features/relation/query_methods/reorder.feature +29 -0
  16. data/features/relation/query_methods/reverse_order.feature +29 -0
  17. data/features/relation/query_methods/select.feature +50 -0
  18. data/features/relation/query_methods/where.feature +70 -0
  19. data/features/step_definitions/connections.rb +65 -0
  20. data/features/step_definitions/model_steps.rb +79 -6
  21. data/features/step_definitions/query_methods.rb +3 -3
  22. data/features/step_definitions/record_steps.rb +3 -4
  23. data/features/support/env.rb +17 -3
  24. data/features/support/world.rb +15 -10
  25. data/gemfiles/3.1.gemfile.lock +15 -15
  26. data/gemfiles/3.2.gemfile.lock +15 -15
  27. data/lib/hydra_attribute/active_record/association.rb +74 -38
  28. data/lib/hydra_attribute/active_record/association_preloader.rb +49 -49
  29. data/lib/hydra_attribute/active_record/attribute_methods.rb +37 -85
  30. data/lib/hydra_attribute/active_record/migration.rb +2 -2
  31. data/lib/hydra_attribute/active_record/reflection.rb +1 -1
  32. data/lib/hydra_attribute/active_record/relation/query_methods.rb +8 -7
  33. data/lib/hydra_attribute/active_record/relation.rb +1 -0
  34. data/lib/hydra_attribute/active_record.rb +20 -12
  35. data/lib/hydra_attribute/association_builder.rb +1 -2
  36. data/lib/hydra_attribute/builder.rb +7 -8
  37. data/lib/hydra_attribute/entity_callbacks.rb +12 -32
  38. data/lib/hydra_attribute/hydra_attribute.rb +25 -16
  39. data/lib/hydra_attribute/hydra_attribute_methods.rb +85 -0
  40. data/lib/hydra_attribute/hydra_methods.rb +123 -0
  41. data/lib/hydra_attribute/hydra_set.rb +36 -0
  42. data/lib/hydra_attribute/hydra_set_methods.rb +39 -0
  43. data/lib/hydra_attribute/hydra_value_methods.rb +14 -0
  44. data/lib/hydra_attribute/memoize.rb +37 -0
  45. data/lib/hydra_attribute/migrator.rb +100 -51
  46. data/lib/hydra_attribute/railtie.rb +1 -3
  47. data/lib/hydra_attribute/version.rb +1 -1
  48. data/lib/hydra_attribute.rb +7 -1
  49. data/spec/hydra_attribute_methods_spec.rb +458 -0
  50. data/spec/hydra_attribute_spec.rb +19 -0
  51. data/spec/hydra_methods_spec.rb +457 -0
  52. data/spec/hydra_set_methods_spec.rb +203 -0
  53. data/spec/hydra_set_spec.rb +19 -0
  54. data/spec/memoize_spec.rb +95 -0
  55. data/spec/spec_helper.rb +42 -2
  56. metadata +71 -43
  57. data/features/create.feature +0 -47
  58. data/features/define.feature +0 -38
  59. data/features/destroy.feature +0 -102
  60. data/features/query_methods/group.feature +0 -42
  61. data/features/query_methods/order.feature +0 -99
  62. data/features/query_methods/select.feature +0 -50
  63. data/features/query_methods/where.feature +0 -70
  64. data/features/support/schema.rb +0 -79
  65. data/features/update.feature +0 -114
data/CHANGELOG.md CHANGED
@@ -1,5 +1,5 @@
1
1
  **0.3.2 (July 31, 2012)**
2
- * Add `white_list` option which allow to add attribute to white list for entity during creation it
2
+ * Add `white_list` option which allows to add attribute to white list for entity during creation
3
3
 
4
4
  **0.3.1 (July 28, 2012)**
5
5
  * Fix bug "ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: name, backend_type, default_value" during creation hydra attributes
data/README.md CHANGED
@@ -64,6 +64,13 @@ class Product < ActiveRecord::Base
64
64
  end
65
65
  ```
66
66
 
67
+ **Starting from version 0.4.0 `use_hydra_attributes` method will be removed.**
68
+ ```ruby
69
+ class Product < ActiveRecord::Base
70
+ include HydraAttribute::ActiveRecord
71
+ end
72
+ ```
73
+
67
74
  ##### Create some hydra attributes from `rails console`
68
75
  ```ruby
69
76
  Product.hydra_attributes.create(name: 'color', backend_type: 'string', default_value: 'green')
@@ -0,0 +1,128 @@
1
+ Feature: create models with hydra attributes
2
+ When create model with hydra attributes
3
+ Then hydra attributes should be saved with default values
4
+
5
+ When hydra set is specified
6
+ Then only attributes from this hydra set should be saved
7
+
8
+ Background: create hydra attributes
9
+ Given create hydra attributes for "Product" with role "admin" as "hashes":
10
+ | name | backend_type | default_value | white_list |
11
+ | code | string | [nil:] | [bool:t] |
12
+ | info | text | [str:] | [bool:t] |
13
+ | total | integer | 0 | [bool:t] |
14
+ | price | float | 0 | [bool:t] |
15
+ | active | boolean | 0 | [bool:t] |
16
+ | started | datetime | 2012-01-01 | [bool:t] |
17
+
18
+ Scenario: don't pass any hydra attributes
19
+ Given create "Product" model
20
+ Then last created "Product" should have the following attributes:
21
+ | code | [nil:] |
22
+ | info | [str:] |
23
+ | price | [float:0] |
24
+ | total | [int:0] |
25
+ | active | [bool:f] |
26
+ | started | [date:2012-01-01] |
27
+
28
+ Scenario: pass two hydra attributes
29
+ Given create "Product" model with attributes as "rows_hash":
30
+ | code | a |
31
+ | price | [nil:] |
32
+ Then last created "Product" should have the following attributes:
33
+ | code | a |
34
+ | info | [str:] |
35
+ | total | [int:0] |
36
+ | price | [nil:] |
37
+ | active | [bool:f] |
38
+ | started | [date:2012-01-01] |
39
+
40
+ Scenario: pass all hydra attributes
41
+ Given create "Product" model with attributes as "rows_hash":
42
+ | code | a |
43
+ | info | b |
44
+ | total | 0 |
45
+ | price | 2 |
46
+ | active | 1 |
47
+ | started | 2012-05-05 |
48
+
49
+ Then last created "Product" should have the following attributes:
50
+ | code | a |
51
+ | price | [float:2] |
52
+ | active | [bool:t] |
53
+ | info | b |
54
+ | started | [date:2012-05-05] |
55
+
56
+ Scenario: pass only hydra_set_id
57
+ Given create hydra sets for "Product" as "hashes":
58
+ | name |
59
+ | Default |
60
+ | General |
61
+ And add "Product" hydra attributes to hydra set:
62
+ | hydra attribute name | hydra set name |
63
+ | code | [array:Default] |
64
+ | price | [array:Default] |
65
+ | active | [array:Default,General] |
66
+ | info | [array:General] |
67
+
68
+ When create "Product" model with attributes as "rows_hash":
69
+ | hydra_set_id | [eval:Product.hydra_sets.find_by_name('Default').id] |
70
+ Then table "hydra_string_products" should have 1 record:
71
+ | entity_id | hydra_attribute_id |
72
+ | [eval:Product.last.id] | [eval:Product.hydra_attributes.find_by_name('code').id] |
73
+ And table "hydra_float_products" should have 1 record:
74
+ | entity_id | hydra_attribute_id |
75
+ | [eval:Product.last.id] | [eval:Product.hydra_attributes.find_by_name('price').id] |
76
+ And table "hydra_boolean_products" should have 1 record:
77
+ | entity_id | hydra_attribute_id |
78
+ | [eval:Product.last.id] | [eval:Product.hydra_attributes.find_by_name('active').id] |
79
+ And table "hydra_text_products" should have 0 records
80
+ And table "hydra_integer_products" should have 0 records
81
+ And table "hydra_datetime_products" should have 0 records
82
+
83
+ When create "Product" model with attributes as "rows_hash":
84
+ | hydra_set_id | [eval:Product.hydra_sets.find_by_name('General').id] |
85
+ And table "hydra_boolean_products" should have 2 records:
86
+ | entity_id | hydra_attribute_id |
87
+ | [eval:Product.last.id] | [eval:Product.hydra_attributes.find_by_name('active').id] |
88
+ And table "hydra_text_products" should have 1 record:
89
+ | entity_id | hydra_attribute_id |
90
+ | [eval:Product.last.id] | [eval:Product.hydra_attributes.find_by_name('info').id] |
91
+ And table "hydra_string_products" should have 1 record:
92
+ | entity_id | hydra_attribute_id |
93
+ | [eval:Product.first.id] | [eval:Product.hydra_attributes.find_by_name('code').id] |
94
+ And table "hydra_float_products" should have 1 record:
95
+ | entity_id | hydra_attribute_id |
96
+ | [eval:Product.first.id] | [eval:Product.hydra_attributes.find_by_name('price').id] |
97
+ And table "hydra_integer_products" should have 0 records
98
+ And table "hydra_datetime_products" should have 0 records
99
+
100
+ Scenario: build model with all attributes, set hydra_set_id and save it
101
+ Given create hydra sets for "Product" as "hashes":
102
+ | name |
103
+ | Default |
104
+ | General |
105
+ And add "Product" hydra attributes to hydra set:
106
+ | hydra attribute name | hydra set name |
107
+ | code | [array:Default] |
108
+ | price | [array:Default] |
109
+ | active | [array:Default,General] |
110
+ | info | [array:General] |
111
+ When build "Product" model:
112
+ | code | #123 |
113
+ | price | 2.50 |
114
+ | active | 1 |
115
+ | info | desc |
116
+ | started | 2012-08-20 |
117
+ And set "hydra_set_id" to "[eval:Product.hydra_sets.find_by_name('General').id]"
118
+ And save model
119
+ Then table "hydra_text_products" should have 1 record:
120
+ | entity_id | hydra_attribute_id |
121
+ | [eval:Product.last.id] | [eval:Product.hydra_attributes.find_by_name('info').id] |
122
+ And table "hydra_boolean_products" should have 1 record:
123
+ | entity_id | hydra_attribute_id |
124
+ | [eval:Product.last.id] | [eval:Product.hydra_attributes.find_by_name('active').id] |
125
+ And table "hydra_float_products" should have 0 records
126
+ And table "hydra_string_products" should have 0 records
127
+ And table "hydra_integer_products" should have 0 records
128
+ And table "hydra_datetime_products" should have 0 records
@@ -0,0 +1,111 @@
1
+ Feature: destroy model
2
+ When destroy model
3
+ Then all associated values should be deleted too
4
+
5
+ Background: create hydra attributes
6
+ Given create hydra attributes for "Product" with role "admin" as "hashes":
7
+ | name | backend_type | default_value | white_list |
8
+ | code | string | | [bool:t] |
9
+ | info | text | [str:] | [bool:t] |
10
+ | total | integer | 0 | [bool:t] |
11
+ | price | float | 0 | [bool:t] |
12
+ | active | boolean | 0 | [bool:t] |
13
+ | started | datetime | 2012-01-01 | [bool:t] |
14
+
15
+ Scenario: destroy model
16
+ Given create "Product" model with attributes as "hashes":
17
+ | code | info | total | price | active | started |
18
+ | 1 | a | 1 | 1.10 | 1 | 2012-01-01 |
19
+ | 2 | b | 2 | 1.20 | 1 | 2012-01-02 |
20
+ | 3 | c | 3 | 1.30 | 0 | 2012-01-03 |
21
+
22
+ Then table "hydra_string_products" should have 3 records:
23
+ | entity_id | hydra_attribute_id | value |
24
+ | 1 | [eval:Product.hydra_attribute('code').id] | 1 |
25
+ | 2 | [eval:Product.hydra_attribute('code').id] | 2 |
26
+ | 3 | [eval:Product.hydra_attribute('code').id] | 3 |
27
+ And table "hydra_text_products" should have 3 records:
28
+ | entity_id | hydra_attribute_id | value |
29
+ | 1 | [eval:Product.hydra_attribute('info').id] | a |
30
+ | 2 | [eval:Product.hydra_attribute('info').id] | b |
31
+ | 3 | [eval:Product.hydra_attribute('info').id] | c |
32
+ And table "hydra_integer_products" should have 3 records:
33
+ | entity_id | hydra_attribute_id | value |
34
+ | 1 | [eval:Product.hydra_attribute('total').id] | 1 |
35
+ | 2 | [eval:Product.hydra_attribute('total').id] | 2 |
36
+ | 3 | [eval:Product.hydra_attribute('total').id] | 3 |
37
+ And table "hydra_float_products" should have 3 records:
38
+ | entity_id | hydra_attribute_id | value |
39
+ | 1 | [eval:Product.hydra_attribute('price').id] | 1.10 |
40
+ | 2 | [eval:Product.hydra_attribute('price').id] | 1.20 |
41
+ | 3 | [eval:Product.hydra_attribute('price').id] | 1.30 |
42
+ And table "hydra_boolean_products" should have 3 records:
43
+ | entity_id | hydra_attribute_id | value |
44
+ | 1 | [eval:Product.hydra_attribute('active').id] | [bool:t] |
45
+ | 2 | [eval:Product.hydra_attribute('active').id] | [bool:t] |
46
+ | 3 | [eval:Product.hydra_attribute('active').id] | [bool:f] |
47
+ And table "hydra_datetime_products" should have 3 records:
48
+ | entity_id | hydra_attribute_id | value |
49
+ | 1 | [eval:Product.hydra_attribute('started').id] | [date:2012-01-01] |
50
+ | 2 | [eval:Product.hydra_attribute('started').id] | [date:2012-01-02] |
51
+ | 3 | [eval:Product.hydra_attribute('started').id] | [date:2012-01-03] |
52
+
53
+ Given select first "Product" record
54
+ And destroy record
55
+
56
+ Then table "hydra_string_products" should have 2 records:
57
+ | entity_id | hydra_attribute_id | value |
58
+ | 2 | [eval:Product.hydra_attribute('code').id] | 2 |
59
+ | 3 | [eval:Product.hydra_attribute('code').id] | 3 |
60
+ And table "hydra_text_products" should have 2 records:
61
+ | entity_id | hydra_attribute_id | value |
62
+ | 2 | [eval:Product.hydra_attribute('info').id] | b |
63
+ | 3 | [eval:Product.hydra_attribute('info').id] | c |
64
+ And table "hydra_integer_products" should have 2 records:
65
+ | entity_id | hydra_attribute_id | value |
66
+ | 2 | [eval:Product.hydra_attribute('total').id] | 2 |
67
+ | 3 | [eval:Product.hydra_attribute('total').id] | 3 |
68
+ And table "hydra_float_products" should have 2 records:
69
+ | entity_id | hydra_attribute_id | value |
70
+ | 2 | [eval:Product.hydra_attribute('price').id] | 1.20 |
71
+ | 3 | [eval:Product.hydra_attribute('price').id] | 1.30 |
72
+ And table "hydra_boolean_products" should have 2 records:
73
+ | entity_id | hydra_attribute_id | value |
74
+ | 2 | [eval:Product.hydra_attribute('active').id] | [bool:t] |
75
+ | 3 | [eval:Product.hydra_attribute('active').id] | [bool:f] |
76
+ And table "hydra_datetime_products" should have 2 records:
77
+ | entity_id | hydra_attribute_id | value |
78
+ | 2 | [eval:Product.hydra_attribute('started').id] | [date:2012-01-02] |
79
+ | 3 | [eval:Product.hydra_attribute('started').id] | [date:2012-01-03] |
80
+
81
+ Given select first "Product" record
82
+ And destroy record
83
+
84
+ Then table "hydra_string_products" should have 1 record:
85
+ | entity_id | hydra_attribute_id | value |
86
+ | 3 | [eval:Product.hydra_attribute('code').id] | 3 |
87
+ And table "hydra_text_products" should have 1 record:
88
+ | entity_id | hydra_attribute_id | value |
89
+ | 3 | [eval:Product.hydra_attribute('info').id] | c |
90
+ And table "hydra_integer_products" should have 1 record:
91
+ | entity_id | hydra_attribute_id | value |
92
+ | 3 | [eval:Product.hydra_attribute('total').id] | 3 |
93
+ And table "hydra_float_products" should have 1 record:
94
+ | entity_id | hydra_attribute_id | value |
95
+ | 3 | [eval:Product.hydra_attribute('price').id] | 1.30 |
96
+ And table "hydra_boolean_products" should have 1 record:
97
+ | entity_id | hydra_attribute_id | value |
98
+ | 3 | [eval:Product.hydra_attribute('active').id] | [bool:f] |
99
+ And table "hydra_datetime_products" should have 1 record:
100
+ | entity_id | hydra_attribute_id | value |
101
+ | 3 | [eval:Product.hydra_attribute('started').id] | [date:2012-01-03] |
102
+
103
+ Given select first "Product" record
104
+ And destroy record
105
+
106
+ Then table "hydra_string_products" should have 0 records
107
+ And table "hydra_text_products" should have 0 records
108
+ And table "hydra_integer_products" should have 0 records
109
+ And table "hydra_float_products" should have 0 records
110
+ And table "hydra_boolean_products" should have 0 records
111
+ And table "hydra_datetime_products" should have 0 records
@@ -0,0 +1,121 @@
1
+ Feature: new entity
2
+ Given new entity should respond to hydra attributes which are saved in hydra_attributes table
3
+
4
+ When hydra attribute was created with white_list flag
5
+ Then it should be allowed through mass-assignment for new entity
6
+
7
+ When hydra_set_id was passed to the new entity
8
+ Then entity should respond only to hydra attributes which were added to this hydra set
9
+ And entity attribute list should include only attributes from hydra set
10
+ And HydraAttribute::MissingAttributeInHydraSetError error should be risen when we call attribute method and this attribute doesn't exist in hydra set
11
+
12
+ Scenario Outline: models should respond to hydra attributes
13
+ Given create hydra attributes for "Product" with role "admin" as "hashes":
14
+ | name | backend_type | white_list |
15
+ | code | string | [bool:t] |
16
+ | price | float | [bool:f] |
17
+ Then model "<model>" <action> respond to "<attributes>"
18
+
19
+ Scenarios: hydra attributes
20
+ | model | action | attributes |
21
+ | Product | should | code |
22
+ | Product | should | code= |
23
+ | Product | should | code? |
24
+ | Product | should | code_before_type_cast |
25
+ | Product | should | code_changed? |
26
+ | Product | should | code_change |
27
+ | Product | should | code_will_change! |
28
+ | Product | should | code_was |
29
+ | Product | should | reset_code! |
30
+ | Product | should | price |
31
+ | Product | should | price= |
32
+ | Product | should | price? |
33
+ | Product | should | price_before_type_cast |
34
+ | Product | should | price_changed? |
35
+ | Product | should | price_change |
36
+ | Product | should | price_will_change! |
37
+ | Product | should | price_was |
38
+ | Product | should | reset_price! |
39
+
40
+ Scenario: model should have appropriate hydra attributes in white list
41
+ Given create hydra attributes for "Product" with role "admin" as "hashes":
42
+ | name | backend_type | white_list |
43
+ | code | string | [bool:t] |
44
+ | price | float | [bool:f] |
45
+ # imitate initialization model class with already created hydra attributes
46
+ When redefine "Product" class to use hydra attributes
47
+ Then class "Product" should have "code" in white list
48
+ And class "Product" should not have "price" in white list
49
+
50
+ Scenario: set hydra_set_id to the new entity
51
+ Given create hydra sets for "Product" as "hashes":
52
+ | name |
53
+ | Default |
54
+ | General |
55
+ And create hydra attributes for "Product" with role "admin" as "hashes":
56
+ | name | backend_type | white_list |
57
+ | code | string | [bool:t] |
58
+ | title | string | [bool:t] |
59
+ | price | float | [bool:t] |
60
+ | total | integer | [bool:t] |
61
+ And add "Product" hydra attributes to hydra set:
62
+ | hydra attribute name | hydra set name |
63
+ | code | [array:Default] |
64
+ | title | [array:Default,General] |
65
+ | price | [array:General] |
66
+
67
+ When build "Product" model:
68
+ | hydra_set_id | [str:[eval:Product.hydra_sets.find_by_name('Default').id]] |
69
+ Then model should respond to "code title"
70
+ And model should not respond to "price total"
71
+
72
+ When build "Product" model:
73
+ | hydra_set_id | [str:[eval:Product.hydra_sets.find_by_name('General').id]] |
74
+ Then model should not respond to "code total"
75
+ And model should respond to "title price"
76
+
77
+ When build "Product" model
78
+ Then model should respond to "code title price total"
79
+
80
+ Scenario: attach and detach hydra set to the same entity
81
+ Given create hydra sets for "Product" as "hashes":
82
+ | name |
83
+ | Default |
84
+ | General |
85
+ And create hydra attributes for "Product" with role "admin" as "hashes":
86
+ | name | backend_type | white_list |
87
+ | title | string | [bool:t] |
88
+ | code | string | [bool:t] |
89
+ | total | integer | [bool:t] |
90
+ | price | float | [bool:t] |
91
+ And add "Product" hydra attributes to hydra set:
92
+ | hydra attribute name | hydra set name |
93
+ | title | [array:Default] |
94
+ | code | [array:Default,General] |
95
+ | total | [array:General] |
96
+
97
+ When build "Product" model
98
+ Then model should respond to "title code total price"
99
+ And model attributes should include "title code total price"
100
+ And error "HydraAttribute::MissingAttributeInHydraSetError" should not be risen when methods "title code total price" are called
101
+
102
+ When set "hydra_set_id" to "[eval:Product.hydra_sets.find_by_name('Default').id]"
103
+ Then model should respond to "title code"
104
+ And model should not respond to "total price"
105
+ And model attributes should include "title code"
106
+ And model attributes should not include "total price"
107
+ And error "HydraAttribute::MissingAttributeInHydraSetError" should be risen when methods "total price" are called
108
+ And error "HydraAttribute::MissingAttributeInHydraSetError" should not be risen when methods "title code" are called
109
+
110
+ When set "hydra_set_id" to "[eval:Product.hydra_sets.find_by_name('General').id]"
111
+ Then model should respond to "code total"
112
+ And model should not respond to "title price"
113
+ And model attributes should include "code total"
114
+ And model attributes should not include "title price"
115
+ And error "HydraAttribute::MissingAttributeInHydraSetError" should be risen when methods "title price" are called
116
+ And error "HydraAttribute::MissingAttributeInHydraSetError" should not be risen when methods "code total" are called
117
+
118
+ When set "hydra_set_id" to "[nil:]"
119
+ Then model should respond to "title code total price"
120
+ And model attributes should include "title code total price"
121
+ And error "HydraAttribute::MissingAttributeInHydraSetError" should not be risen when methods "title code total price" are called
@@ -0,0 +1,147 @@
1
+ Feature: update hydra attributes
2
+ When update hydra attribute
3
+ Then updated_at for entity should be updated
4
+
5
+ When update hydra_set_id
6
+ Then entity should have hydra attributes from this hydra set
7
+
8
+ Background: create hydra attributes
9
+ Given create hydra attributes for "Product" with role "admin" as "hashes":
10
+ | name | backend_type | default_value | white_list |
11
+ | code | string | ### | [bool:t] |
12
+ | title | string | | [bool:t] |
13
+ | info | text | | [bool:t] |
14
+ | total | integer | 1 | [bool:t] |
15
+ | price | float | | [bool:t] |
16
+ | launch | datetime | | [bool:t] |
17
+ And create "Product" model
18
+
19
+ Scenario Outline: update attributes
20
+ Given select last "Product" record
21
+ When assign attributes as "rows_hash":
22
+ | code | <set code> |
23
+ | title | <set title> |
24
+ | total | <set total> |
25
+ And save record
26
+ Then last created "Product" should have the following attributes:
27
+ | code | <code> |
28
+ | title | <title> |
29
+ | total | <total> |
30
+
31
+ Scenarios: attributes
32
+ | set code | set title | set total | code | title | total |
33
+ | a | b | [int:2] | a | b | [int:2] |
34
+ | [str:] | [str:] | [nil:] | [str:] | [str:] | [nil:] |
35
+ | | | 3 | ### | [nil:] | [int:3] |
36
+
37
+ Scenario: update the same model several times to test touch method
38
+ Given select first "Product" record
39
+ And save record
40
+ Then last created "Product" should have the following attributes:
41
+ | code | ### |
42
+ | title | [nil:] |
43
+ | total | [int:1] |
44
+
45
+ When assign attributes as "rows_hash":
46
+ | title | [str:] |
47
+ | total | [nil:] |
48
+ And save record
49
+ Then last created "Product" should have the following attributes:
50
+ | code | ### |
51
+ | title | [str:] |
52
+ | total | [nil:] |
53
+
54
+ When assign attributes as "rows_hash":
55
+ | code | a |
56
+ | total | 2 |
57
+ And save record
58
+ Then last created "Product" should have the following attributes:
59
+ | code | a |
60
+ | title | [str:] |
61
+ | total | [int:2] |
62
+
63
+ When assign attributes as "rows_hash":
64
+ | title | b |
65
+ And save record
66
+ Then last created "Product" should have the following attributes:
67
+ | code | a |
68
+ | title | b |
69
+ | total | [int:2] |
70
+
71
+ Scenario: touch entity when attribute is updated
72
+ Given select last "Product" record
73
+ And keep "updated_at" attribute
74
+ And save record
75
+ Then attribute "updated_at" should be the same
76
+
77
+ Given select last "Product" record
78
+ And keep "updated_at" attribute
79
+ When assign attributes as "rows_hash":
80
+ | code | ### |
81
+ | total | [int:1] |
82
+ And save record
83
+ Then attribute "updated_at" should be the same
84
+
85
+ Given select last "Product" record
86
+ And keep "updated_at" attribute
87
+ When assign attributes as "rows_hash":
88
+ | code | [nil:] |
89
+ And save record
90
+ Then attribute "updated_at" should not be the same
91
+
92
+ Given select last "Product" record
93
+ And keep "updated_at" attribute
94
+ When assign attributes as "rows_hash":
95
+ | code | [nil:] |
96
+ And save record
97
+ Then attribute "updated_at" should be the same
98
+
99
+ Given select last "Product" record
100
+ And keep "updated_at" attribute
101
+ When assign attributes as "rows_hash":
102
+ | total | [nil:] |
103
+ And save record
104
+ Then attribute "updated_at" should not be the same
105
+
106
+ Given select last "Product" record
107
+ And keep "updated_at" attribute
108
+ When assign attributes as "rows_hash":
109
+ | code | [str:] |
110
+ And save record
111
+ Then attribute "updated_at" should not be the same
112
+
113
+ Given select last "Product" record
114
+ And keep "updated_at" attribute
115
+ When assign attributes as "rows_hash":
116
+ | title | [str:] |
117
+ | total | [int:0] |
118
+ And save record
119
+ Then attribute "updated_at" should not be the same
120
+
121
+ Scenario: update hydra_set_id
122
+ Given create hydra sets for "Product" as "hashes":
123
+ | name |
124
+ | Default |
125
+ | General |
126
+ And add "Product" hydra attributes to hydra set:
127
+ | hydra attribute name | hydra set name |
128
+ | code | [array:Default] |
129
+ | title | [array:Default] |
130
+ | info | [array:Default,General] |
131
+ | total | [array:General] |
132
+ | price | [array:General] |
133
+ And create "Product" model
134
+ And find last "Product" model
135
+
136
+ When set "hydra_set_id" to "[eval:Product.hydra_sets.find_by_name('Default').id]"
137
+ And reload model
138
+ Then model attributes should include "code title info"
139
+
140
+ When set "hydra_set_id" to "[eval:Product.hydra_sets.find_by_name('General').id]"
141
+ And reload model
142
+ Then model attributes should include "info total price"
143
+
144
+ When set "hydra_set_id" to "[nil:]"
145
+ And reload model
146
+ Then model attributes should include "code title info total price launch"
147
+
@@ -4,8 +4,8 @@ Feature: create hydra attributes
4
4
 
5
5
  Background: create hydra attributes
6
6
  Given create hydra attributes for "Product" with role "admin" as "hashes":
7
- | name | backend_type | white_list |
8
- | [string:price] | [string:float] | [boolean:true] |
7
+ | name | backend_type | white_list |
8
+ | price | float | [bool:t] |
9
9
 
10
10
  Scenario: create hydra attribute
11
11
  # Important: when respond_to? is called the hydra attributes are being loaded for entity class
@@ -17,14 +17,14 @@ Feature: create hydra attributes
17
17
 
18
18
  Scenario: create attribute but don't add it to white list
19
19
  Given create hydra attributes for "Product" with role "admin" as "hashes":
20
- | name | backend_type | white_list |
21
- | [string:code] | [string:string] | |
22
- | [string:total] | [string:integer] | [boolean:false] |
20
+ | name | backend_type | white_list |
21
+ | code | string | |
22
+ | total | integer | [bool:f] |
23
23
  Then class "Product" should not have "code" in white list
24
24
  And class "Product" should not have "total" in white list
25
25
 
26
26
  Scenario: create attribute and add it to white list
27
27
  Given create hydra attributes for "Product" with role "admin" as "hashes":
28
- | name | backend_type | white_list |
29
- | [string:code] | [string:string] | [boolean:true] |
28
+ | name | backend_type | white_list |
29
+ | code | string | [bool:t] |
30
30
  Then class "Product" should have "code" in white list
@@ -5,16 +5,14 @@ Feature: destroy hydra attributes
5
5
 
6
6
  Background: create hydra attributes
7
7
  Given create hydra attributes for "Product" with role "admin" as "hashes":
8
- | name | backend_type | white_list |
9
- | [string:price] | [string:float] | [boolean:true] |
10
-
8
+ | name | backend_type | white_list |
9
+ | price | float | [bool:t] |
11
10
 
12
11
  Scenario: entity should not respond to removed attribute
13
12
  When destroy all "HydraAttribute::HydraAttribute" models with attributes as "rows_hash":
14
13
  |name | price |
15
14
  Then model "Product" should not respond to "price"
16
15
 
17
-
18
16
  Scenario: remove all values from appropriate table
19
17
  Given create "Product" model with attributes as "rows_hash":
20
18
  | price | 10 |
@@ -4,8 +4,8 @@ Feature: update hydra attribute
4
4
 
5
5
  Background: create hydra attributes
6
6
  Given create hydra attributes for "Product" with role "admin" as "hashes":
7
- | name | backend_type | default_value | white_list |
8
- | [string:code] | [string:integer] | [integer:1] | [boolean:true] |
7
+ | name | backend_type | default_value | white_list |
8
+ | code | integer | 1 | [bool:t] |
9
9
 
10
10
  Scenario: update default value
11
11
  Given create "Product" model
@@ -13,24 +13,24 @@ Feature: update hydra attribute
13
13
  | default_value | 2 |
14
14
  And create "Product" model
15
15
  Then first created "Product" should have the following attributes:
16
- | code | [integer:1] |
16
+ | code | [int:1] |
17
17
  And last created "Product" should have the following attributes:
18
- | code | [integer:2] |
18
+ | code | [int:2] |
19
19
 
20
20
  Scenario: update white list attribute to true
21
21
  Given create hydra attributes for "Product" with role "admin" as "hashes":
22
- | name | backend_type | white_list |
23
- | [string:title] | [string:string] | [boolean:false] |
22
+ | name | backend_type | white_list |
23
+ | title | string | [bool:f] |
24
24
  And select last "HydraAttribute::HydraAttribute" record
25
25
  When update attributes as "admin":
26
- | white_list | [boolean:true] |
26
+ | white_list | [bool:t] |
27
27
  Then class "Product" should have "title" in white list
28
28
 
29
29
  Scenario: update white list attribute to false
30
30
  Given create hydra attributes for "Product" with role "admin" as "hashes":
31
- | name | backend_type | white_list |
32
- | [string:info] | [string:string] | [boolean:true] |
31
+ | name | backend_type | white_list |
32
+ | info | string | [bool:t] |
33
33
  And select last "HydraAttribute::HydraAttribute" record
34
34
  When update attributes as "admin":
35
- | white_list | [boolean:false] |
35
+ | white_list | [bool:f] |
36
36
  Then class "Product" should not have "info" in white list
@@ -0,0 +1,31 @@
1
+ Feature: destroy hydra set
2
+ When destroy hydra set
3
+ Then column hydra_set_id should be set to NULL for entity table
4
+
5
+ Background: create hydra set and add hydra attributes to it
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
+ And create hydra set "Default" for "Product"
12
+ And add "Product" hydra attributes to hydra set:
13
+ | hydra attribute name | hydra set name |
14
+ | code | [array:Default] |
15
+ | state | [array:Default] |
16
+ And create "Product" model with attributes as "rows_hash":
17
+ | hydra_set_id | [eval:Product.hydra_sets.find_by_name('Default').id] |
18
+
19
+ Scenario: after removing hydra set the hydra_set_id for entity should be NULL
20
+ When destroy all "HydraAttribute::HydraSet" models with attributes as "rows_hash":
21
+ | name | Default|
22
+ Then table "products" should have 1 record:
23
+ | hydra_set_id |
24
+ | [nil:] |
25
+ And last created "Product" should have attribute "hydra_set_id" with value "[nil:]"
26
+
27
+ Scenario: after removing hydra set entity should respond to all hydra attributes
28
+ Given destroy all "HydraAttribute::HydraSet" models with attributes as "rows_hash":
29
+ | name | Default|
30
+ When find last "Product" model
31
+ Then model attributes should match "[array:id,hydra_set_id,name,created_at,updated_at,code,state,title]"