hydra_attribute 0.3.2 → 0.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,99 +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
- When reorder by attributes
12
- Then old hydra attributes should be removed and new should be added
13
-
14
- Background: create hydra attributes
15
- Given create hydra attributes for "Product" with role "admin" as "hashes":
16
- | name | backend_type | white_list |
17
- | [string:code] | [string:integer] | [boolean:true] |
18
- | [string:state] | [string:integer] | [boolean:true] |
19
- | [string:title] | [string:string] | [boolean:true] |
20
-
21
- Scenario Outline: order by one field
22
- Given create "Product" model with attributes as "hashes":
23
- | name | code | state |
24
- | [string:c] | [integer:1] | [integer:1] |
25
- | [string:b] | [integer:2] | [integer:2] |
26
- | [string:a] | [integer:3] | [integer:3] |
27
- When order "Product" records by "<attributes>"
28
- Then "first" record should have "<first identifier>"
29
- And "last" record should have "<last identifier>"
30
-
31
- Scenarios: order conditions
32
- | attributes | first identifier | last identifier |
33
- | state=asc | code=[integer:1] | code=[integer:3] |
34
- | state=desc | code=[integer:3] | code=[integer:1] |
35
- | name=asc | code=[integer:3] | code=[integer:1] |
36
- | name=desc | code=[integer:1] | code=[integer:3] |
37
-
38
- Scenario Outline: order by several attributes
39
- Given create "Product" model with attributes as "hashes":
40
- | name | code | state | title |
41
- | [string:c] | [integer:1] | [integer:1] | [string:b] |
42
- | [string:b] | [integer:2] | [integer:2] | [string:a] |
43
- | [string:a] | [integer:3] | [integer:3] | [string:c] |
44
- When order "Product" records by "<attributes>"
45
- Then "first" record should have "<first identifier>"
46
- And "last" record should have "<last identifier>"
47
-
48
- Scenarios: order conditions
49
- | attributes | first identifier | last identifier |
50
- | name state | code=[integer:3] | code=[integer:1] |
51
- | state title | code=[integer:1] | code=[integer:3] |
52
- | title state | code=[integer:2] | code=[integer:3] |
53
-
54
- Scenario Outline: order by filtered attribute
55
- Given create "Product" model with attributes as "hashes":
56
- | code | state | title |
57
- | [integer:1] | [integer:1] | |
58
- | [integer:2] | | [nil:] |
59
- | [integer:3] | [integer:1] | [string:a] |
60
- When filter "Product" records by "<filter attribute>"
61
- And order records by "<order attributes>"
62
- Then total records should be "<count>"
63
- And "first" record should have "<first identifier>"
64
- And "last" record should have "<last identifier>"
65
-
66
- Scenarios: order conditions
67
- | filter attribute | order attributes | count | first identifier | last identifier |
68
- | state=[integer:1] | state code | 2 | code=[integer:1] | code=[integer:3] |
69
- | state=[nil:] | state code | 1 | code=[integer:2] | code=[integer:2] |
70
- | title=[nil:] | title code | 2 | code=[integer:1] | code=[integer:2] |
71
-
72
- Scenario Outline: reorder
73
- Given create "Product" model with attributes as "hashes":
74
- | code | name | title |
75
- | [integer:1] | [string:a] | [string:c] |
76
- | [integer:2] | [string:b] | [string:b] |
77
- | [integer:3] | [string:c] | [string:a] |
78
- When order "Product" records by "<order>"
79
- And reorder records by "<reorder>"
80
- Then total records should be "<count>"
81
- And "first" record should have "<first identifier>"
82
- And "last" record should have "<last identifier>"
83
-
84
- Scenarios: order conditions
85
- | order | reorder | count | first identifier | last identifier |
86
- | title | name title | 3 | code=[integer:1] | code=[integer:3] |
87
- | name | title name | 3 | code=[integer:3] | code=[integer:1] |
88
-
89
- Scenario: reverse order
90
- Given create "Product" model with attributes as "hashes":
91
- | code | title |
92
- | [integer:1] | [string:a] |
93
- | [integer:2] | [string:b] |
94
- | [integer:3] | [string:c] |
95
- When order "Product" records by "title"
96
- And reverse order records
97
- Then total records should be "3"
98
- And "first" record should have "code=[integer:3]"
99
- And "last" record should have "code=[integer:1]"
@@ -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
- | [string:code] | [string:integer] | [boolean:true] |
9
- | [string:price] | [string:float] | [boolean:true] |
10
- | [string:title] | [string:string] | [boolean:true] |
11
- | [string:note] | [string:text] | [boolean:true] |
12
- | [string:active] | [string:boolean] | [boolean:true] |
13
- | [string:schedule] | [string:datetime] | [boolean:true] |
14
- And create "Product" model with attributes as "hashes":
15
- | name | code | price | title | note | active | schedule |
16
- | [string:a] | [integer:1] | [float:4] | [string:q] | [string:z] | [boolean:true] | [datetime:2012-06-01] |
17
- | [string:b] | [integer:2] | [float:5] | [string:w] | [string:x] | [boolean:false] | [datetime:2012-06-02] |
18
- | [string:c] | [integer:3] | [float:6] | | [string:c] | [boolean:true] | [datetime:2012-06-03] |
19
- | [string:d] | [nil:] | [float:7] | | [string:v] | [boolean:false] | [datetime: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 | name | code price title note active schedule |
30
- | name code | id name code | price title note active schedule |
31
- | name code price | id name code price | title note active schedule |
32
- | code price title | id code price title | name note active schedule |
33
- | title note active | id title note active | name code price schedule |
34
- | schedule | id schedule | name code price title note active |
35
- | id schedule | 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 name code | name=[string:a] | price title note active schedule | 1 |
47
- | code | id code | code=[integer:1] | name price title note active schedule | 1 |
48
- | name code | id name code | code=[integer:1] | price title note active schedule | 1 |
49
- | code title | id code title | title=[nil:] | name price note active schedule | 2 |
50
- | code note | id code note | title=[nil:] | name price title active schedule | 2 |
@@ -1,70 +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
- | [string:code] | [string:string] | [boolean:true] |
12
- | [string:summary] | [string:string] | [boolean:true] |
13
- | [string:title] | [string:string] | [boolean:true] |
14
- | [string:price] | [string:float] | [boolean:true] |
15
- | [string:active] | [string:boolean] | [boolean:true] |
16
- | [string:state] | [string:integer] | [boolean:true] |
17
-
18
- Scenario: filter by one hydra attribute
19
- Given create "Product" model with attributes as "hashes":
20
- | code | price |
21
- | [string:1] | [float:2.75] |
22
- | [string:2] | [float:2.75] |
23
- | [string:3] | [float:2.76] |
24
- | [string:4] | [nil:] |
25
- When filter "Product" by:
26
- | field | value |
27
- | price | [string:2.75] |
28
- Then total records should be "2"
29
- And records should have the following attributes:
30
- | field | value |
31
- | code | [string:1] |
32
- | code | [string: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
- | [string:1] | [nil:] |
38
- | [string:2] | [float:0] |
39
- | [string: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 | [string:1] |
47
- | code | [string: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
- | [string:toy] | [string:1] | [string:story] | [float:2.40] | [boolean:true] | | |
53
- | [string:toy] | [string:2] | [string:story] | [float:2.45] | [boolean:true] | | [nil:] |
54
- | [string:toy] | [string:3] | [string:story] | [float:2.45] | [boolean:true] | [nil:] | [nil:] |
55
- | [string:toy] | [string:4] | | [float:2.45] | [boolean:false] | [nil:] | [nil:] |
56
- | | [string:5] | | [float:2.45] | [boolean:true] | [nil:] | [nil:] |
57
- | [string:toy] | [string:6] | | [float:2.46] | [boolean:true] | [nil:] | [nil:] |
58
- When filter "Product" by:
59
- | field | value |
60
- | name | [string:toy] |
61
- | title | [string:story] |
62
- | summary | [nil:] |
63
- | price | [string:2.45] |
64
- | active | [boolean:true] |
65
- | state | [nil:] |
66
- Then total records should be "2"
67
- And records should have the following attributes:
68
- | field | value |
69
- | code | [string:2] |
70
- | code | [string:3] |
@@ -1,79 +0,0 @@
1
- ActiveRecord::Schema.define do
2
- create_table "products", :force => true do |t|
3
- t.string "name"
4
- t.datetime "created_at", :null => false
5
- t.datetime "updated_at", :null => false
6
- end
7
-
8
- create_table "hydra_attributes", :force => true do |t|
9
- t.string "entity_type", :limit => 32, :null => false
10
- t.string "name", :limit => 32, :null => false
11
- t.string "backend_type", :limit => 16, :null => false
12
- t.string "default_value"
13
- t.boolean "white_list", :null => false, :default => false
14
- t.datetime "created_at", :null => false
15
- t.datetime "updated_at", :null => false
16
- end
17
-
18
- add_index "hydra_attributes", ["entity_type", "name"], :name => "hydra_attributes_index", :unique => true
19
-
20
- create_table "hydra_boolean_products", :force => true do |t|
21
- t.integer "entity_id", :null => false
22
- t.integer "hydra_attribute_id", :null => false
23
- t.boolean "value"
24
- t.datetime "created_at", :null => false
25
- t.datetime "updated_at", :null => false
26
- end
27
-
28
- add_index "hydra_boolean_products", ["entity_id", "hydra_attribute_id"], :name => "hydra_boolean_products_index", :unique => true
29
-
30
- create_table "hydra_datetime_products", :force => true do |t|
31
- t.integer "entity_id", :null => false
32
- t.integer "hydra_attribute_id", :null => false
33
- t.datetime "value"
34
- t.datetime "created_at", :null => false
35
- t.datetime "updated_at", :null => false
36
- end
37
-
38
- add_index "hydra_datetime_products", ["entity_id", "hydra_attribute_id"], :name => "hydra_datetime_products_index", :unique => true
39
-
40
- create_table "hydra_float_products", :force => true do |t|
41
- t.integer "entity_id", :null => false
42
- t.integer "hydra_attribute_id", :null => false
43
- t.float "value"
44
- t.datetime "created_at", :null => false
45
- t.datetime "updated_at", :null => false
46
- end
47
-
48
- add_index "hydra_float_products", ["entity_id", "hydra_attribute_id"], :name => "hydra_float_products_index", :unique => true
49
-
50
- create_table "hydra_integer_products", :force => true do |t|
51
- t.integer "entity_id", :null => false
52
- t.integer "hydra_attribute_id", :null => false
53
- t.integer "value"
54
- t.datetime "created_at", :null => false
55
- t.datetime "updated_at", :null => false
56
- end
57
-
58
- add_index "hydra_integer_products", ["entity_id", "hydra_attribute_id"], :name => "hydra_integer_products_index", :unique => true
59
-
60
- create_table "hydra_string_products", :force => true do |t|
61
- t.integer "entity_id", :null => false
62
- t.integer "hydra_attribute_id", :null => false
63
- t.string "value"
64
- t.datetime "created_at", :null => false
65
- t.datetime "updated_at", :null => false
66
- end
67
-
68
- add_index "hydra_string_products", ["entity_id", "hydra_attribute_id"], :name => "hydra_string_products_index", :unique => true
69
-
70
- create_table "hydra_text_products", :force => true do |t|
71
- t.integer "entity_id", :null => false
72
- t.integer "hydra_attribute_id", :null => false
73
- t.text "value"
74
- t.datetime "created_at", :null => false
75
- t.datetime "updated_at", :null => false
76
- end
77
-
78
- add_index "hydra_text_products", ["entity_id", "hydra_attribute_id"], :name => "hydra_text_products_index", :unique => true
79
- end
@@ -1,114 +0,0 @@
1
- Feature: update hydra attributes
2
- When update attribute
3
- Then entity should be touched
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
- | [string:code] | [string:string] | [string:###] | [boolean:true] |
9
- | [string:title] | [string:string] | | [boolean:true] |
10
- | [string:total] | [string:integer] | [integer:1] | [boolean:true] |
11
- And create "Product" model
12
-
13
- Scenario Outline: update attributes
14
- Given select last "Product" record
15
- When assign attributes as "rows_hash":
16
- | code | <set code> |
17
- | title | <set title> |
18
- | total | <set total> |
19
- And save record
20
- Then last created "Product" should have the following attributes:
21
- | code | <code> |
22
- | title | <title> |
23
- | total | <total> |
24
-
25
- Scenarios: attributes
26
- | set code | set title | set total | code | title | total |
27
- | [string:a] | [string:b] | [integer:2] | [string:a] | [string:b] | [integer:2] |
28
- | [string:] | [string:] | [nil:] | [string:] | [string:] | [nil:] |
29
- | | | [string:3] | [string:###] | [nil:] | [integer:3] |
30
-
31
- # Is a better solution to call several scenarios but don't call hooks and backgrounds before?
32
- Scenario: update the same model several times
33
- Given select first "Product" record
34
- And save record
35
- Then last created "Product" should have the following attributes:
36
- | code | [string:###] |
37
- | title | [nil:] |
38
- | total | [integer:1] |
39
-
40
- When assign attributes as "rows_hash":
41
- | title | [string:] |
42
- | total | [nil:] |
43
- And save record
44
- Then last created "Product" should have the following attributes:
45
- | code | [string:###] |
46
- | title | [string:] |
47
- | total | [nil:] |
48
-
49
- When assign attributes as "rows_hash":
50
- | code | [string:a] |
51
- | total | [string:2] |
52
- And save record
53
- Then last created "Product" should have the following attributes:
54
- | code | [string:a] |
55
- | title | [string:] |
56
- | total | [integer:2] |
57
-
58
- When assign attributes as "rows_hash":
59
- | title | [string:b] |
60
- And save record
61
- Then last created "Product" should have the following attributes:
62
- | code | [string:a] |
63
- | title | [string:b] |
64
- | total | [integer:2] |
65
-
66
- Scenario: touch entity when attribute is updated
67
- Given select last "Product" record
68
- And keep "updated_at" attribute
69
- And save record
70
- Then attribute "updated_at" should be the same
71
-
72
- Given select last "Product" record
73
- And keep "updated_at" attribute
74
- When assign attributes as "rows_hash":
75
- | code | [string:###] |
76
- | total | [integer:1] |
77
- And save record
78
- Then attribute "updated_at" should be the same
79
-
80
- Given select last "Product" record
81
- And keep "updated_at" attribute
82
- When assign attributes as "rows_hash":
83
- | code | [nil:] |
84
- And save record
85
- Then attribute "updated_at" should not be the same
86
-
87
- Given select last "Product" record
88
- And keep "updated_at" attribute
89
- When assign attributes as "rows_hash":
90
- | code | [nil:] |
91
- And save record
92
- Then attribute "updated_at" should be the same
93
-
94
- Given select last "Product" record
95
- And keep "updated_at" attribute
96
- When assign attributes as "rows_hash":
97
- | total | [nil:] |
98
- And save record
99
- Then attribute "updated_at" should not be the same
100
-
101
- Given select last "Product" record
102
- And keep "updated_at" attribute
103
- When assign attributes as "rows_hash":
104
- | code | [string:] |
105
- And save record
106
- Then attribute "updated_at" should not be the same
107
-
108
- Given select last "Product" record
109
- And keep "updated_at" attribute
110
- When assign attributes as "rows_hash":
111
- | title | [string:] |
112
- | total | [integer:0] |
113
- And save record
114
- Then attribute "updated_at" should not be the same