hydra_attribute 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/Appraisals +7 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +122 -0
- data/Rakefile +12 -0
- data/features/attribute_methods.feature +151 -0
- data/features/define_attributes.feature +61 -0
- data/features/load_associations.feature +45 -0
- data/features/order_conditions.feature +93 -0
- data/features/select_attributes.feature +56 -0
- data/features/step_definitions/class_steps.rb +32 -0
- data/features/step_definitions/model_steps.rb +31 -0
- data/features/step_definitions/record_steps.rb +103 -0
- data/features/support/env.rb +24 -0
- data/features/support/schema.rb +51 -0
- data/features/support/world.rb +31 -0
- data/features/typecast_attributes.feature +29 -0
- data/features/where_conditions.feature +77 -0
- data/gemfiles/3.1.gemfile +7 -0
- data/gemfiles/3.1.gemfile.lock +60 -0
- data/gemfiles/3.2.gemfile +7 -0
- data/gemfiles/3.2.gemfile.lock +60 -0
- data/hydra_attribute.gemspec +24 -0
- data/lib/generators/hydra_attribute/install/USAGE +8 -0
- data/lib/generators/hydra_attribute/install/install_generator.rb +11 -0
- data/lib/generators/hydra_attribute/install/templates/hydra_attribute.txt +11 -0
- data/lib/hydra_attribute.rb +31 -0
- data/lib/hydra_attribute/active_record.rb +7 -0
- data/lib/hydra_attribute/active_record/attribute_methods.rb +72 -0
- data/lib/hydra_attribute/active_record/attribute_methods/before_type_cast.rb +16 -0
- data/lib/hydra_attribute/active_record/attribute_methods/read.rb +13 -0
- data/lib/hydra_attribute/active_record/relation.rb +44 -0
- data/lib/hydra_attribute/active_record/relation/query_methods.rb +162 -0
- data/lib/hydra_attribute/active_record/scoping.rb +15 -0
- data/lib/hydra_attribute/association_builder.rb +40 -0
- data/lib/hydra_attribute/attribute_builder.rb +57 -0
- data/lib/hydra_attribute/attribute_proxy.rb +16 -0
- data/lib/hydra_attribute/builder.rb +25 -0
- data/lib/hydra_attribute/configuration.rb +47 -0
- data/lib/hydra_attribute/migration.rb +27 -0
- data/lib/hydra_attribute/railtie.rb +9 -0
- data/lib/hydra_attribute/version.rb +3 -0
- data/spec/hydra_attribute/active_record/relation/query_methods_spec.rb +286 -0
- data/spec/hydra_attribute/active_record/relation_spec.rb +93 -0
- data/spec/hydra_attribute/active_record/scoping_spec.rb +19 -0
- data/spec/hydra_attribute/active_record_spec.rb +20 -0
- data/spec/hydra_attribute/association_builder_spec.rb +95 -0
- data/spec/hydra_attribute/attribute_builder_spec.rb +70 -0
- data/spec/hydra_attribute/attribute_helpers_spec.rb +70 -0
- data/spec/hydra_attribute/builder_spec.rb +39 -0
- data/spec/hydra_attribute/configuration_spec.rb +96 -0
- data/spec/hydra_attribute_spec.rb +20 -0
- data/spec/spec_helper.rb +17 -0
- metadata +196 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Appraisals
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Kostyantyn Stepanyuk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# hydra_attribute
|
2
|
+
|
3
|
+
hydra_attribute is an implementation of
|
4
|
+
[EAV pattern](http://en.wikipedia.org/wiki/Entity–attribute–value_model) for ActiveRecord models.
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
* ruby >= 1.9.2
|
8
|
+
* active_record >= 3.1
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add the following line to Gemfile:
|
13
|
+
```ruby
|
14
|
+
gem 'hydra_attribute'
|
15
|
+
```
|
16
|
+
and run `bundle install` from your shell.
|
17
|
+
|
18
|
+
After successful installation run rails generator:
|
19
|
+
```shell
|
20
|
+
rails generate hydra_attribute:install
|
21
|
+
```
|
22
|
+
|
23
|
+
This command generates hydra_attribute initializer:
|
24
|
+
```ruby
|
25
|
+
HydraAttribute.setup do |config|
|
26
|
+
# Add prefix for all attribute tables
|
27
|
+
# config.table_prefix = 'hydra_'
|
28
|
+
|
29
|
+
# Add prefix for has_many associations
|
30
|
+
# config.association_prefix = 'hydra_'
|
31
|
+
|
32
|
+
# Wrap all associated models in HydraAttribute module
|
33
|
+
# config.use_module_for_associated_models = true
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
And the last step is to generate db:migration:
|
38
|
+
```shell
|
39
|
+
rails generate migration create_hydra_attrubute_tables
|
40
|
+
```
|
41
|
+
Migration should look like this:
|
42
|
+
```ruby
|
43
|
+
class CreateHydraAttributeTables < ActiveRecord::Migration
|
44
|
+
def up
|
45
|
+
HydraAttribute::Migration.new(self).migrate
|
46
|
+
end
|
47
|
+
|
48
|
+
def down
|
49
|
+
HydraAttribute::Migration.new(self).rollback
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
## Usage
|
54
|
+
|
55
|
+
##### Generate model
|
56
|
+
```shell
|
57
|
+
rails generate model Product type:string name:string
|
58
|
+
rails generate model SimpleProduct --migration=false --parent=Product
|
59
|
+
rake db:migrate
|
60
|
+
```
|
61
|
+
|
62
|
+
##### Describe EAV attributes
|
63
|
+
```ruby
|
64
|
+
class SimpleProduct < Product
|
65
|
+
attr_accessible :name, :title, :code, :quantity, :price, :active, :description
|
66
|
+
|
67
|
+
define_hydra_attributes do |hydra|
|
68
|
+
hydra.string :title, :code
|
69
|
+
hydra.integer :quantity
|
70
|
+
hydra.float :price
|
71
|
+
hydra.boolean :active
|
72
|
+
hydra.text :description
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
##### Create some products
|
78
|
+
```shell
|
79
|
+
SimpleProduct.create(name: 'Book', title: 'book', code: '100', quantity: 5, price: 2.75, active: true, description: '...')
|
80
|
+
SimpleProduct.create(name: 'Book', title: 'book', code: '101', quantity: 5, price: 3.75, active: true, description: '...')
|
81
|
+
SimpleProduct.create(name: 'Book', title: 'book', code: '102', quantity: 4, price: 4.50, active: false, description: '...')
|
82
|
+
SimpleProduct.create(name: 'Book', title: nil, code: '103', quantity: 3, price: 4.50, active: true, description: '...')
|
83
|
+
SimpleProduct.create(name: 'Book', code: '104', quantity: 2, price: 5.00, active: true, description: '...')
|
84
|
+
```
|
85
|
+
|
86
|
+
##### "where"
|
87
|
+
```shell
|
88
|
+
SimpleProduct.where(name: 'Book', quantity: 5, price: 2.75).first.attributes
|
89
|
+
=> {"id"=>1, "type"=>"SimpleProduct", "name"=>"Book", "created_at"=>Tue, 05 Jun 2012 23:13:21 UTC +00:00, "updated_at"=>Tue, 05 Jun 2012 23:13:21 UTC +00:00, "title"=>"book", "code"=>"100", "quantity"=>5, "price"=>2.75, "active"=>true, "description"=>"..."}
|
90
|
+
|
91
|
+
SimpleProduct.where(title: 'book', active: false).first.attributes
|
92
|
+
=> {"id"=>3, "type"=>"SimpleProduct", "name"=>"Book", "created_at"=>Tue, 05 Jun 2012 23:13:50 UTC +00:00, "updated_at"=>Tue, 05 Jun 2012 23:13:50 UTC +00:00, "title"=>"book", "code"=>"102", "quantity"=>4, "price"=>4.5, "active"=>false, "description"=>"..."}
|
93
|
+
|
94
|
+
SimpleProduct.where(title: nil).first.attributes
|
95
|
+
=> {"id"=>4, "type"=>"SimpleProduct", "name"=>"Book", "created_at"=>Tue, 05 Jun 2012 23:13:50 UTC +00:00, "updated_at"=>Tue, 05 Jun 2012 23:13:50 UTC +00:00, "title"=>nil, "code"=>"103", "quantity"=>3, "price"=>4.5, "active"=>true, "description"=>"..."}
|
96
|
+
|
97
|
+
SimpleProduct.where(title: nil).last.attributes
|
98
|
+
=> {"id"=>5, "type"=>"SimpleProduct", "name"=>"Book", "created_at"=>Tue, 05 Jun 2012 23:13:51 UTC +00:00, "updated_at"=>Tue, 05 Jun 2012 23:13:51 UTC +00:00, "title"=>nil, "code"=>"104", "quantity"=>2, "price"=>5.0, "active"=>true, "description"=>"..."}
|
99
|
+
```
|
100
|
+
|
101
|
+
##### "order" and "reverse_order"
|
102
|
+
```shell
|
103
|
+
SimpleProduct.order(:code).first.attributes
|
104
|
+
=> {"id"=>1, "type"=>"SimpleProduct", "name"=>"Book", "created_at"=>Tue, 05 Jun 2012 23:30:48 UTC +00:00, "updated_at"=>Tue, 05 Jun 2012 23:30:49 UTC +00:00, "title"=>"book", "code"=>"100", "quantity"=>5, "price"=>2.75, "active"=>true, "description"=>"..."}
|
105
|
+
|
106
|
+
SimpleProduct.order(:code).reverse_order.first.attributes
|
107
|
+
=> {"id"=>5, "type"=>"SimpleProduct", "name"=>"Book", "created_at"=>Tue, 05 Jun 2012 23:30:51 UTC +00:00, "updated_at"=>Tue, 05 Jun 2012 23:30:51 UTC +00:00, "title"=>nil, "code"=>"104", "quantity"=>2, "price"=>5.0, "active"=>true, "description"=>"..."}
|
108
|
+
```
|
109
|
+
|
110
|
+
##### "select"
|
111
|
+
```shell
|
112
|
+
SimpleProduct.select([:code, :price]).map(&:attributes)
|
113
|
+
=> [{"code"=>"100", "price"=>2.75}, {"code"=>"101", "price"=>3.75}, {"code"=>"102", "price"=>4.5}, {"code"=>"103", "price"=>4.5}, {"code"=>"104", "price"=>5.0}]
|
114
|
+
```
|
115
|
+
|
116
|
+
## Contributing
|
117
|
+
|
118
|
+
1. Fork it
|
119
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
120
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
121
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
122
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'appraisal'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new('spec')
|
8
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
9
|
+
t.cucumber_opts = '--format pretty'
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :spec
|
@@ -0,0 +1,151 @@
|
|
1
|
+
Feature: helper methods for hydra attributes
|
2
|
+
When class calls hydra_attributes
|
3
|
+
Then symbolize hash with hydra attribute names and their types should be returned
|
4
|
+
|
5
|
+
When class calls hydra_attribute_names
|
6
|
+
Then array with symbolize hydra attribute names should be returned
|
7
|
+
|
8
|
+
When class calls hydra_attribute_types
|
9
|
+
Then array with symbolize hydra attribute types should be returned
|
10
|
+
|
11
|
+
When model calls hydra_attributes
|
12
|
+
Then stringify hash with hydra attribute names and their values should be returned
|
13
|
+
|
14
|
+
When model calls attributes
|
15
|
+
Then stringify hash with both native and hydra attributes should be returned
|
16
|
+
|
17
|
+
When model calls attributes_before_type_cast
|
18
|
+
Then stringify hash with both native and hydra attributes should be returned with values before type cast
|
19
|
+
|
20
|
+
When model calls read_attribute on hydra attribute
|
21
|
+
Then hydra attribute value should be returned
|
22
|
+
|
23
|
+
When model calls read_attribute_before_type_cast
|
24
|
+
Then hydra attribute value before type cast should be returned
|
25
|
+
|
26
|
+
Background: create models and describe hydra attributes
|
27
|
+
Given removed constants if they exist:
|
28
|
+
| name |
|
29
|
+
| GroupProduct |
|
30
|
+
| SimpleProduct |
|
31
|
+
| Product |
|
32
|
+
And create model class "Product"
|
33
|
+
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
34
|
+
| type | name |
|
35
|
+
| string | code |
|
36
|
+
| float | price |
|
37
|
+
| text | note |
|
38
|
+
And create model class "GroupProduct" as "Product" with hydra attributes:
|
39
|
+
| type | name |
|
40
|
+
| integer | price |
|
41
|
+
| string | title |
|
42
|
+
| boolean | active |
|
43
|
+
| datetime | launch |
|
44
|
+
|
45
|
+
Scenario Outline: class hydra_attributes
|
46
|
+
Then class "<class>"::"<method>" "<behavior>" have "<param>" hash
|
47
|
+
|
48
|
+
Scenarios: hydra attributes
|
49
|
+
| class | method | behavior | param |
|
50
|
+
| SimpleProduct | hydra_attributes | should | code=string price=float note=text |
|
51
|
+
| GroupProduct | hydra_attributes | should | price=integer title=string active=boolean launch=datetime |
|
52
|
+
|
53
|
+
Scenario Outline: class hydra_attribute_names
|
54
|
+
Then class "<class>"::"<method>" "<behavior>" have string "<params>" in array
|
55
|
+
|
56
|
+
Scenarios: hydra attribute names
|
57
|
+
| class | method | behavior | params |
|
58
|
+
| SimpleProduct | hydra_attribute_names | should | code price note |
|
59
|
+
| SimpleProduct | hydra_attribute_names | should_not | title active launch |
|
60
|
+
| GroupProduct | hydra_attribute_names | should | price title active launch |
|
61
|
+
| GroupProduct | hydra_attribute_names | should_not | code note |
|
62
|
+
|
63
|
+
Scenario Outline: class hydra_attribute_types
|
64
|
+
Then class "<class>"::"<method>" "<behavior>" have symbol "<params>" in array
|
65
|
+
|
66
|
+
Scenarios: hydra attribute types
|
67
|
+
| class | method | behavior | params |
|
68
|
+
| SimpleProduct | hydra_attribute_types | should | string float text |
|
69
|
+
| SimpleProduct | hydra_attribute_types | should_not | integer boolean datetime |
|
70
|
+
| GroupProduct | hydra_attribute_types | should | integer string boolean datetime |
|
71
|
+
| GroupProduct | hydra_attribute_types | should_not | text float |
|
72
|
+
|
73
|
+
Scenario Outline: model hydra_attributes
|
74
|
+
Given create models:
|
75
|
+
| model | attributes |
|
76
|
+
| SimpleProduct | name=[string:a] info=[string:i] code=[string:c] price=[float:2] note=[string:n] |
|
77
|
+
| GroupProduct | name=[string:a] info=[string:i] price=[float:2] title=[string:t] active=[boolean:true] launch=[string:2012-06-03] |
|
78
|
+
When select "first" "<model>" record
|
79
|
+
Then model "<model>" should have only the following hydra attributes "<attributes>"
|
80
|
+
And record should have the following hydra attributes "<values>" in attribute hash
|
81
|
+
|
82
|
+
Scenarios: required hydra attributes
|
83
|
+
| model | attributes | values |
|
84
|
+
| SimpleProduct | code price note | code=[string:c] price=[float:2] note=[string:n] |
|
85
|
+
| GroupProduct | price title active launch | price=[float:2] title=[string:t] active=[boolean:true] launch=[string:2012-06-03] |
|
86
|
+
|
87
|
+
Scenario Outline: model attributes
|
88
|
+
Given create models:
|
89
|
+
| model | attributes |
|
90
|
+
| SimpleProduct | name=[string:a] info=[string:i] code=[string:c] price=[float:2] note=[string:n] |
|
91
|
+
| GroupProduct | name=[string:a] info=[string:i] price=[float:2] title=[string:t] active=[boolean:true] launch=[string:2012-06-03] |
|
92
|
+
When select "first" "<model>" record
|
93
|
+
Then model "<model>" should have only the following attributes "<attributes>"
|
94
|
+
And record should have the following attributes "<values>" in attribute hash
|
95
|
+
|
96
|
+
Scenarios: required attributes
|
97
|
+
| model | attributes | values |
|
98
|
+
| SimpleProduct | id type name info created_at updated_at code price note | name=[string:a] info=[string:i] code=[string:c] price=[float:2] note=[string:n] |
|
99
|
+
| GroupProduct | id type name info created_at updated_at price title active launch | name=[string:a] info=[string:i] price=[float:2] title=[string:t] active=[boolean:true] launch=[string:2012-06-03] |
|
100
|
+
|
101
|
+
Scenario Outline: model attributes_before_type_cast
|
102
|
+
Given create models:
|
103
|
+
| model | attributes |
|
104
|
+
| SimpleProduct | name=[string:a] info=[string:i] code=[string:c] price=[float:2] note=[string:n] |
|
105
|
+
| GroupProduct | name=[string:a] info=[string:i] price=[float:2] title=[string:t] active=[boolean:true] launch=[string:2012-06-07] |
|
106
|
+
When select "first" "<model>" record
|
107
|
+
Then model "<model>" should have only the following attributes before type cast "<attributes>"
|
108
|
+
And record should have the following attributes before type cast "<before type cast values>" in attribute hash
|
109
|
+
|
110
|
+
Scenarios: required before type cast attributes
|
111
|
+
| model | attributes | before type cast values |
|
112
|
+
| SimpleProduct | id type name info created_at updated_at code price note | name=[string:a] info=[string:i] code=[string:c] price=[float:2] note=[string:n] |
|
113
|
+
| GroupProduct | id type name info created_at updated_at price title active launch | name=[string:a] info=[string:i] price=[float:2] title=[string:t] active=[string:t] launch=[string:2012-06-07 00:00:00.000000] |
|
114
|
+
|
115
|
+
Scenario Outline: model read_attributes
|
116
|
+
Given create models:
|
117
|
+
| model | attributes |
|
118
|
+
| SimpleProduct | name=[string:a] info=[string:i] code=[string:c] price=[nil:] |
|
119
|
+
| GroupProduct | name=[string:a] info=[string:i] price=[nil:] active=[boolean:true] launch=[string:2012-06-03] |
|
120
|
+
When select "first" "<model>" record
|
121
|
+
Then record read attribute "<attribute>" and value should be "<value>"
|
122
|
+
|
123
|
+
Scenarios: read attributes
|
124
|
+
| model | attribute | value |
|
125
|
+
| SimpleProduct | name | [string:a] |
|
126
|
+
| SimpleProduct | info | [string:i] |
|
127
|
+
| SimpleProduct | code | [string:c] |
|
128
|
+
| SimpleProduct | price | [nil:] |
|
129
|
+
| SimpleProduct | note | [nil:] |
|
130
|
+
| GroupProduct | name | [string:a] |
|
131
|
+
| GroupProduct | info | [string:i] |
|
132
|
+
| GroupProduct | price | [nil:] |
|
133
|
+
| GroupProduct | title | [nil:] |
|
134
|
+
| GroupProduct | active | [boolean:true] |
|
135
|
+
| GroupProduct | launch | [datetime:2012-06-03] |
|
136
|
+
|
137
|
+
Scenario Outline: model read_attributes_before_type_cast
|
138
|
+
Given create models:
|
139
|
+
| model | attributes |
|
140
|
+
| SimpleProduct | name=[string:a] price=[float:2] |
|
141
|
+
| GroupProduct | name=[string:a] active=[boolean:false] launch=[string:2012-06-03] |
|
142
|
+
When select "first" "<model>" record
|
143
|
+
Then record read attribute before type cast "<attribute>" and value should be "<value>"
|
144
|
+
|
145
|
+
Scenarios: read attributes
|
146
|
+
| model | attribute | value |
|
147
|
+
| SimpleProduct | name | [string:a] |
|
148
|
+
| SimpleProduct | price | [float:2] |
|
149
|
+
| GroupProduct | name | [string:a] |
|
150
|
+
| GroupProduct | active | [string:f] |
|
151
|
+
| GroupProduct | launch | [string:2012-06-03 00:00:00.000000] |
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Feature: define hydra attributes
|
2
|
+
Models should respond to hydra attributes
|
3
|
+
|
4
|
+
Model should respond to hydra attributes if they are described in the class.
|
5
|
+
Model should not respond to hydra attribute if it isn't described in it class.
|
6
|
+
|
7
|
+
Background: create models and describe hydra attributes
|
8
|
+
Given removed constants if they exist:
|
9
|
+
| name |
|
10
|
+
| GroupProduct |
|
11
|
+
| SimpleProduct |
|
12
|
+
| Product |
|
13
|
+
And create model class "Product"
|
14
|
+
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
15
|
+
| type | name |
|
16
|
+
| string | code |
|
17
|
+
And create model class "GroupProduct" as "Product" with hydra attributes:
|
18
|
+
| type | name |
|
19
|
+
| float | price |
|
20
|
+
|
21
|
+
Scenario Outline: models should respond to hydra attributes
|
22
|
+
Then model "<model>" should "<respond>" to "<attributes>"
|
23
|
+
|
24
|
+
Scenarios: model should respond to own hydra attributes
|
25
|
+
| model | respond | attributes |
|
26
|
+
| SimpleProduct | should | code |
|
27
|
+
| SimpleProduct | should | code= |
|
28
|
+
| SimpleProduct | should | code? |
|
29
|
+
| SimpleProduct | should | code_before_type_cast |
|
30
|
+
| SimpleProduct | should | code_changed? |
|
31
|
+
| SimpleProduct | should | code_change |
|
32
|
+
| SimpleProduct | should | code_will_change! |
|
33
|
+
| SimpleProduct | should | code_was |
|
34
|
+
| SimpleProduct | should | reset_code! |
|
35
|
+
| SimpleProduct | should_not | price |
|
36
|
+
| SimpleProduct | should_not | price= |
|
37
|
+
| SimpleProduct | should_not | price? |
|
38
|
+
| SimpleProduct | should_not | price_before_type_cast |
|
39
|
+
| SimpleProduct | should_not | price_changed? |
|
40
|
+
| SimpleProduct | should_not | price_change |
|
41
|
+
| SimpleProduct | should_not | price_will_change! |
|
42
|
+
| SimpleProduct | should_not | price_was |
|
43
|
+
| SimpleProduct | should_not | reset_price! |
|
44
|
+
| GroupProduct | should | price |
|
45
|
+
| GroupProduct | should | price= |
|
46
|
+
| GroupProduct | should | price? |
|
47
|
+
| GroupProduct | should | price_before_type_cast |
|
48
|
+
| GroupProduct | should | price_changed? |
|
49
|
+
| GroupProduct | should | price_change |
|
50
|
+
| GroupProduct | should | price_will_change! |
|
51
|
+
| GroupProduct | should | price_was |
|
52
|
+
| GroupProduct | should | reset_price! |
|
53
|
+
| GroupProduct | should_not | code |
|
54
|
+
| GroupProduct | should_not | code= |
|
55
|
+
| GroupProduct | should_not | code? |
|
56
|
+
| GroupProduct | should_not | code_before_type_cast |
|
57
|
+
| GroupProduct | should_not | code_changed? |
|
58
|
+
| GroupProduct | should_not | code_change |
|
59
|
+
| GroupProduct | should_not | code_will_change! |
|
60
|
+
| GroupProduct | should_not | code_was |
|
61
|
+
| GroupProduct | should_not | reset_code! |
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Feature: hydra attribute associations
|
2
|
+
When loaded collection has more than one record
|
3
|
+
Then all hydra attribute associations should be loaded
|
4
|
+
|
5
|
+
When loaded collection hasn't records or has only one
|
6
|
+
Then hydra attribute association should not be loaded automatically
|
7
|
+
|
8
|
+
Background: create models and describe hydra attributes
|
9
|
+
Given removed constants if they exist:
|
10
|
+
| name |
|
11
|
+
| GroupProduct |
|
12
|
+
| SimpleProduct |
|
13
|
+
| Product |
|
14
|
+
And create model class "Product"
|
15
|
+
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
16
|
+
| type | name |
|
17
|
+
| string | code |
|
18
|
+
| float | price |
|
19
|
+
And create model class "GroupProduct" as "Product" with hydra attributes:
|
20
|
+
| type | name |
|
21
|
+
| float | price |
|
22
|
+
| string | title |
|
23
|
+
| boolean | active |
|
24
|
+
|
25
|
+
Scenario: hydra attribute associations should be included for collection with more then one record
|
26
|
+
Given create models:
|
27
|
+
| model | attributes |
|
28
|
+
| SimpleProduct | code=[integer:1] |
|
29
|
+
| SimpleProduct | code=[integer:2] |
|
30
|
+
When load all "SimpleProduct" records
|
31
|
+
Then records "should" have loaded associations:
|
32
|
+
| association |
|
33
|
+
| hydra_string_attributes |
|
34
|
+
| hydra_float_attributes |
|
35
|
+
|
36
|
+
Scenario: hydra attribute associations should not be included for collection with one record
|
37
|
+
Given create models:
|
38
|
+
| model | attributes |
|
39
|
+
| GroupProduct | price=[float:2.75] |
|
40
|
+
When load all "GroupProduct" records
|
41
|
+
Then records "should_not" have loaded associations:
|
42
|
+
| association |
|
43
|
+
| hydra_float_attributes |
|
44
|
+
| hydra_string_attributes |
|
45
|
+
| hydra_boolean_attributes |
|