hydra_attribute 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/README.md +6 -0
- data/features/attribute_methods.feature +1 -6
- data/features/define_attributes.feature +1 -6
- data/features/load_associations.feature +1 -6
- data/features/query_methods/group.feature +43 -0
- data/features/{order_conditions.feature → query_methods/order.feature} +1 -6
- data/features/{select_attributes.feature → query_methods/select.feature} +1 -6
- data/features/{where_conditions.feature → query_methods/where.feature} +1 -6
- data/features/step_definitions/query_methods.rb +44 -0
- data/features/step_definitions/record_steps.rb +4 -39
- data/features/support/env.rb +3 -0
- data/features/typecast_attributes.feature +1 -6
- data/gemfiles/3.1.gemfile.lock +1 -1
- data/gemfiles/3.2.gemfile.lock +1 -1
- data/lib/hydra_attribute/active_record/relation/query_methods.rb +4 -3
- data/lib/hydra_attribute/active_record/relation.rb +6 -2
- data/lib/hydra_attribute/configuration.rb +0 -8
- data/lib/hydra_attribute/version.rb +1 -1
- data/spec/hydra_attribute/active_record/relation/query_methods_spec.rb +4 -4
- data/spec/hydra_attribute/active_record/relation_spec.rb +29 -55
- data/spec/hydra_attribute/active_record/scoping_spec.rb +6 -2
- data/spec/hydra_attribute/configuration_spec.rb +0 -31
- metadata +29 -22
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -114,6 +114,12 @@ SimpleProduct.select([:code, :price]).map(&:attributes)
|
|
114
114
|
=> [{"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}]
|
115
115
|
```
|
116
116
|
|
117
|
+
##### "group"
|
118
|
+
```shell
|
119
|
+
SimpleProduct.group(:name, :price).count
|
120
|
+
=> {["Book", 2.75]=>1, ["Book", 3.75]=>1, ["Book", 4.5]=>2, ["Book", 5.0]=>1}
|
121
|
+
```
|
122
|
+
|
117
123
|
## Contributing
|
118
124
|
|
119
125
|
1. Fork it
|
@@ -24,12 +24,7 @@ Feature: helper methods for hydra attributes
|
|
24
24
|
Then hydra attribute value before type cast should be returned
|
25
25
|
|
26
26
|
Background: create models and describe hydra attributes
|
27
|
-
Given
|
28
|
-
| name |
|
29
|
-
| GroupProduct |
|
30
|
-
| SimpleProduct |
|
31
|
-
| Product |
|
32
|
-
And create model class "Product"
|
27
|
+
Given create model class "Product"
|
33
28
|
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
34
29
|
| type | name |
|
35
30
|
| string | code |
|
@@ -5,12 +5,7 @@ Feature: define hydra attributes
|
|
5
5
|
Model should not respond to hydra attribute if it isn't described in it class.
|
6
6
|
|
7
7
|
Background: create models and describe hydra attributes
|
8
|
-
Given
|
9
|
-
| name |
|
10
|
-
| GroupProduct |
|
11
|
-
| SimpleProduct |
|
12
|
-
| Product |
|
13
|
-
And create model class "Product"
|
8
|
+
Given create model class "Product"
|
14
9
|
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
15
10
|
| type | name |
|
16
11
|
| string | code |
|
@@ -6,12 +6,7 @@ Feature: hydra attribute associations
|
|
6
6
|
Then hydra attribute association should not be loaded automatically
|
7
7
|
|
8
8
|
Background: create models and describe hydra attributes
|
9
|
-
Given
|
10
|
-
| name |
|
11
|
-
| GroupProduct |
|
12
|
-
| SimpleProduct |
|
13
|
-
| Product |
|
14
|
-
And create model class "Product"
|
9
|
+
Given create model class "Product"
|
15
10
|
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
16
11
|
| type | name |
|
17
12
|
| string | code |
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Feature: group conditions by hydra attributes
|
2
|
+
When group by hydra attribute
|
3
|
+
Then correct table should be joined and group condition should be added
|
4
|
+
|
5
|
+
Background: create models and describe hydra attributes
|
6
|
+
Given create model class "Product"
|
7
|
+
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
8
|
+
| type | name |
|
9
|
+
| integer | code |
|
10
|
+
| string | title |
|
11
|
+
| integer | total |
|
12
|
+
And create models:
|
13
|
+
| model | attributes |
|
14
|
+
| SimpleProduct | name=[string:a] code=[integer:1] title=[string:q] total=[integer:5] |
|
15
|
+
| SimpleProduct | name=[string:b] code=[integer:2] title=[string:w] total=[integer:5] |
|
16
|
+
| SimpleProduct | name=[string:b] code=[integer:3] title=[string:w] total=[nil:] |
|
17
|
+
| SimpleProduct | name=[string:c] code=[integer:4] title=[string:e] |
|
18
|
+
|
19
|
+
Scenario Outline: group by attributes
|
20
|
+
When group "SimpleProduct" by "<group by>"
|
21
|
+
Then total records should be "<total>"
|
22
|
+
And "first" record should have "<first attribute>"
|
23
|
+
And "last" record should have "<last attribute>"
|
24
|
+
|
25
|
+
Scenarios: group attributes
|
26
|
+
| group by | total | first attribute | last attribute |
|
27
|
+
| code | 4 | code=[integer:1] | code=[integer:4] |
|
28
|
+
| name | 3 | name=[string:a] code=[integer:1] | name=[string:c] code=[integer:4] |
|
29
|
+
| name title | 3 | name=[string:a] code=[integer:1] | name=[string:c] code=[integer:4] |
|
30
|
+
|
31
|
+
Scenario Outline: group by attributes with filter
|
32
|
+
When group "SimpleProduct" by "<group by>"
|
33
|
+
And filter records by "<filter>"
|
34
|
+
Then total records should be "<total>"
|
35
|
+
And "first" record should have "<first attribute>"
|
36
|
+
And "last" record should have "<last attribute>"
|
37
|
+
|
38
|
+
Scenarios: group attributes
|
39
|
+
| group by | filter | total | first attribute | last attribute |
|
40
|
+
| code | title=[string:w] | 2 | code=[integer:2] | code=[integer:3] |
|
41
|
+
| name | title=[string:w] | 1 | name=[string:b] title=[string:w] | name=[string:b] title=[string:w] |
|
42
|
+
| name title | title=[string:w] | 1 | name=[string:b] title=[string:w] | name=[string:b] title=[string:w] |
|
43
|
+
| name title | total=[nil:] | 2 | name=[string:b] title=[string:w] | name=[string:c] title=[string:e] |
|
@@ -12,12 +12,7 @@ Feature: order conditions by hydra attributes
|
|
12
12
|
Then old hydra attributes should be removed and new should be added
|
13
13
|
|
14
14
|
Background: create models and describe hydra attributes
|
15
|
-
Given
|
16
|
-
| name |
|
17
|
-
| GroupProduct |
|
18
|
-
| SimpleProduct |
|
19
|
-
| Product |
|
20
|
-
And create model class "Product"
|
15
|
+
Given create model class "Product"
|
21
16
|
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
22
17
|
| type | name |
|
23
18
|
| integer | code |
|
@@ -3,12 +3,7 @@ Feature: select concrete attributes
|
|
3
3
|
Then hydra attribute table should be joined and concrete attribute should be selected
|
4
4
|
|
5
5
|
Background: create models and describe hydra attributes
|
6
|
-
Given
|
7
|
-
| name |
|
8
|
-
| GroupProduct |
|
9
|
-
| SimpleProduct |
|
10
|
-
| Product |
|
11
|
-
And create model class "Product"
|
6
|
+
Given create model class "Product"
|
12
7
|
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
13
8
|
| type | name |
|
14
9
|
| integer | code |
|
@@ -6,12 +6,7 @@ Feature: hydra attribute where conditions
|
|
6
6
|
Then records with nil value should be selected or records which don't have this hydra attribute
|
7
7
|
|
8
8
|
Background: create models and describe hydra attributes
|
9
|
-
Given
|
10
|
-
| name |
|
11
|
-
| GroupProduct |
|
12
|
-
| SimpleProduct |
|
13
|
-
| Product |
|
14
|
-
And create model class "Product"
|
9
|
+
Given create model class "Product"
|
15
10
|
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
16
11
|
| type | name |
|
17
12
|
| string | code |
|
@@ -0,0 +1,44 @@
|
|
1
|
+
When /^filter "([^"]+)" by:$/ do |klass, table|
|
2
|
+
condition = table.hashes.each_with_object({}) { |item, hash| hash[item[:field].to_sym] = typecast_value(item[:value]) }
|
3
|
+
@records = Object.const_get(klass).where(condition)
|
4
|
+
end
|
5
|
+
|
6
|
+
When /^filter "([^"]+)" records by "([^"]+)"$/ do |klass, attribute|
|
7
|
+
@records = Object.const_get(klass)
|
8
|
+
step %Q(filter records by "#{attribute}")
|
9
|
+
end
|
10
|
+
|
11
|
+
When /^filter records by "([^"]+)"$/ do |attribute|
|
12
|
+
name, value = typecast_attribute(attribute)
|
13
|
+
@records = @records.where(name => value)
|
14
|
+
end
|
15
|
+
|
16
|
+
When /^group "([^"]+)" by "([^"]+)"$/ do |klass, attributes|
|
17
|
+
@records = Object.const_get(klass)
|
18
|
+
step %Q(group by "#{attributes}")
|
19
|
+
end
|
20
|
+
|
21
|
+
When /^group by "([^"]+)"$/ do |attributes|
|
22
|
+
@records = @records.group(attributes.split)
|
23
|
+
end
|
24
|
+
|
25
|
+
When /^(order|reorder) "([^"]+)" records by "([^"]+)"$/ do |sort_method, klass, attributes|
|
26
|
+
@records = Object.const_get(klass)
|
27
|
+
step %Q(#{sort_method} records by "#{attributes}")
|
28
|
+
end
|
29
|
+
|
30
|
+
When /^(order|reorder) records by "([^"]+)"$/ do |sort_method, attributes|
|
31
|
+
reverse = false
|
32
|
+
fields = attributes.split.inject([]) do |items, attribute|
|
33
|
+
name, direction = attribute.split('=')
|
34
|
+
reverse = true if direction == 'desc'
|
35
|
+
items << name.to_sym
|
36
|
+
end
|
37
|
+
|
38
|
+
@records = @records.send(sort_method, fields)
|
39
|
+
@records = @records.reverse_order if reverse
|
40
|
+
end
|
41
|
+
|
42
|
+
When /^"([^"]+)" select only the following columns "([^"]+)"$/ do |klass, columns|
|
43
|
+
@records = Object.const_get(klass).select(columns.split(/\s+/).map(&:to_sym))
|
44
|
+
end
|
@@ -6,42 +6,6 @@ When /^select "(first|last)" "([^"]+)" record$/ do |method, klass|
|
|
6
6
|
@record = Object.const_get(klass).send(method)
|
7
7
|
end
|
8
8
|
|
9
|
-
When /^filter "([^"]+)" by:$/ do |klass, table|
|
10
|
-
condition = table.hashes.each_with_object({}) { |item, hash| hash[item[:field].to_sym] = typecast_value(item[:value]) }
|
11
|
-
@records = Object.const_get(klass).where(condition)
|
12
|
-
end
|
13
|
-
|
14
|
-
When /^filter "([^"]+)" records by "([^"]+)"$/ do |klass, attribute|
|
15
|
-
@records = Object.const_get(klass)
|
16
|
-
step %Q(filter records by "#{attribute}")
|
17
|
-
end
|
18
|
-
|
19
|
-
When /^filter records by "([^"]+)"$/ do |attribute|
|
20
|
-
name, value = typecast_attribute(attribute)
|
21
|
-
@records = @records.where(name => value)
|
22
|
-
end
|
23
|
-
|
24
|
-
When /^(order|reorder) "([^"]+)" records by "([^"]+)"$/ do |sort_method, klass, attributes|
|
25
|
-
@records = Object.const_get(klass)
|
26
|
-
step %Q(#{sort_method} records by "#{attributes}")
|
27
|
-
end
|
28
|
-
|
29
|
-
When /^(order|reorder) records by "([^"]+)"$/ do |sort_method, attributes|
|
30
|
-
reverse = false
|
31
|
-
fields = attributes.split.inject([]) do |items, attribute|
|
32
|
-
name, direction = attribute.split('=')
|
33
|
-
reverse = true if direction == 'desc'
|
34
|
-
items << name.to_sym
|
35
|
-
end
|
36
|
-
|
37
|
-
@records = @records.send(sort_method, fields)
|
38
|
-
@records = @records.reverse_order if reverse
|
39
|
-
end
|
40
|
-
|
41
|
-
When /^"([^"]+)" select only the following columns "([^"]+)"$/ do |klass, columns|
|
42
|
-
@records = Object.const_get(klass).select(columns.split(/\s+/).map(&:to_sym))
|
43
|
-
end
|
44
|
-
|
45
9
|
Then /^record should have the following ((?:hydra )?attributes(?: before type cast)?) "([^"]+)" in attribute hash$/ do |method, attributes|
|
46
10
|
method = method.gsub(/\s+/, '_')
|
47
11
|
typecast_attributes(attributes).each do |(name, value)|
|
@@ -55,8 +19,9 @@ Then /^record (read attribute(?: before type cast)?) "([^"]+)" and value should
|
|
55
19
|
end
|
56
20
|
|
57
21
|
Then /^"(first|last)" record should have "([^"]+)"$/ do |method, attribute|
|
58
|
-
name, value
|
59
|
-
|
22
|
+
typecast_attributes(attribute).each do |(name, value)|
|
23
|
+
@records.send(method).send(name).should == value
|
24
|
+
end
|
60
25
|
end
|
61
26
|
|
62
27
|
Then /^records should have the following attributes:$/ do |table|
|
@@ -82,7 +47,7 @@ Then /^records should raise "([^"]+)" when call the following "([^"]+)"$/ do |er
|
|
82
47
|
end
|
83
48
|
|
84
49
|
Then /^total records should be "([^"]+)"$/ do |count|
|
85
|
-
@records.should have(count.to_i).items
|
50
|
+
@records.to_a.should have(count.to_i).items
|
86
51
|
end
|
87
52
|
|
88
53
|
Then /^records "(should|should_not)" have loaded associations:$/ do |should, table|
|
data/features/support/env.rb
CHANGED
@@ -15,6 +15,9 @@ Before do
|
|
15
15
|
const = HydraAttribute.config.associated_const_name(type)
|
16
16
|
HydraAttribute.send(:remove_const, const) if HydraAttribute.const_defined?(const)
|
17
17
|
end
|
18
|
+
[:Product, :SimpleProduct, :GroupProduct].each do |const|
|
19
|
+
Object.send(:remove_const, const) if Object.const_defined?(const)
|
20
|
+
end
|
18
21
|
ActiveSupport::Dependencies::Reference.clear!
|
19
22
|
DatabaseCleaner.start
|
20
23
|
end
|
@@ -2,12 +2,7 @@ Feature: create model
|
|
2
2
|
Model should be created with typecast hydra attributes.
|
3
3
|
|
4
4
|
Background: create models and describe hydra attributes
|
5
|
-
Given
|
6
|
-
| name |
|
7
|
-
| GroupProduct |
|
8
|
-
| SimpleProduct |
|
9
|
-
| Product |
|
10
|
-
And create model class "Product"
|
5
|
+
Given create model class "Product"
|
11
6
|
And create model class "SimpleProduct" as "Product" with hydra attributes:
|
12
7
|
| type | name |
|
13
8
|
| string | code |
|
data/gemfiles/3.1.gemfile.lock
CHANGED
data/gemfiles/3.2.gemfile.lock
CHANGED
@@ -39,10 +39,11 @@ module HydraAttribute
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def build_arel
|
42
|
-
@
|
42
|
+
@group_values = build_hydra_values_for_arel(@group_values.uniq.reject(&:blank?))
|
43
|
+
@order_values = build_hydra_values_for_arel(@order_values.uniq.reject(&:blank?))
|
43
44
|
|
44
45
|
if instance_variable_defined?(:@reorder_value) and instance_variable_get(:@reorder_value).present? # for compatibility with 3.1.x
|
45
|
-
@reorder_value =
|
46
|
+
@reorder_value = build_hydra_values_for_arel(@reorder_value.uniq.reject(&:blank?))
|
46
47
|
end
|
47
48
|
|
48
49
|
@hydra_select_values, @select_values = @select_values.partition { |value| klass.hydra_attribute_names.include?(value.to_s) }
|
@@ -94,7 +95,7 @@ module HydraAttribute
|
|
94
95
|
@hydra_attr_helper ||= Helper.new(self)
|
95
96
|
end
|
96
97
|
|
97
|
-
def
|
98
|
+
def build_hydra_values_for_arel(collection)
|
98
99
|
collection.map do |attribute|
|
99
100
|
attribute = attribute.respond_to?(:to_sql) ? attribute.to_sql : attribute.to_s
|
100
101
|
if klass.hydra_attribute_names.include?(attribute)
|
@@ -5,11 +5,15 @@ module HydraAttribute
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
include QueryMethods
|
8
|
+
|
9
|
+
target = ::ActiveRecord::VERSION::STRING.starts_with?('3.1.') ? :to_a : :exec_queries
|
10
|
+
alias_method :__old_exec_queries__, target
|
11
|
+
alias_method target, :__exec_queries__
|
8
12
|
end
|
9
13
|
|
10
|
-
|
14
|
+
def __exec_queries__
|
11
15
|
return @records if loaded?
|
12
|
-
records =
|
16
|
+
records = __old_exec_queries__
|
13
17
|
return records if records.empty?
|
14
18
|
|
15
19
|
limit_values = select_values.any? || hydra_select_values.any?
|
@@ -93,13 +93,13 @@ describe HydraAttribute::ActiveRecord::Relation::QueryMethods do
|
|
93
93
|
end
|
94
94
|
|
95
95
|
it 'should update @order_values before generate the arel object' do
|
96
|
-
relation.stub(
|
96
|
+
relation.stub(build_hydra_values_for_arel: %w(build_order))
|
97
97
|
relation.build_arel.should == arel
|
98
98
|
relation.instance_variable_get(:@order_values).should == %w(build_order)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
describe '#
|
102
|
+
describe '#build_hydra_values_for_arel' do
|
103
103
|
let(:connection) do
|
104
104
|
conn = mock
|
105
105
|
conn.stub(:quote_column_name) { |column| column.to_s }
|
@@ -124,14 +124,14 @@ describe HydraAttribute::ActiveRecord::Relation::QueryMethods do
|
|
124
124
|
|
125
125
|
describe 'collection has not hydra attributes' do
|
126
126
|
it 'should return the same collection' do
|
127
|
-
relation.send(:
|
127
|
+
relation.send(:build_hydra_values_for_arel, %w(name zone)).should == %w(product.name product.zone)
|
128
128
|
relation.joins_values.should == []
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
describe 'collection has hydra attributes' do
|
133
133
|
it 'should change hydra attributes and join hydra tables' do
|
134
|
-
relation.send(:
|
134
|
+
relation.send(:build_hydra_values_for_arel, %w(name code title price)).should == %w(product.name code_inner.value title_.value price_.value)
|
135
135
|
relation.joins_values.should == %w(price__join)
|
136
136
|
end
|
137
137
|
end
|
@@ -1,91 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe HydraAttribute::ActiveRecord::Relation do
|
4
|
-
def record_class(loaded_associations = false)
|
5
|
-
Class.new do
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
[:string]
|
10
|
-
end
|
11
|
-
|
12
|
-
define_singleton_method :hydra_attribute_names do
|
13
|
-
['code']
|
14
|
-
end
|
15
|
-
|
16
|
-
define_singleton_method :hydra_attributes do
|
17
|
-
@hydra_attributes
|
18
|
-
end
|
19
|
-
|
20
|
-
define_method :association do |_|
|
21
|
-
Class.new do
|
22
|
-
define_singleton_method :loaded? do
|
23
|
-
loaded_associations
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
5
|
+
let(:record_class) do
|
6
|
+
mock(:record_class, hydra_attribute_types: [:string], hydra_attribute_names: %w(code), hydra_attributes: {'code' => :string})
|
28
7
|
end
|
29
8
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
false
|
34
|
-
end
|
9
|
+
let(:record) do
|
10
|
+
mock(:record, class: record_class, association: mock(loaded?: false))
|
11
|
+
end
|
35
12
|
|
36
|
-
|
37
|
-
|
38
|
-
|
13
|
+
let(:loaded_record) do
|
14
|
+
mock(:loaded_record, class: record_class, association: mock(loaded?: true))
|
15
|
+
end
|
39
16
|
|
40
|
-
|
41
|
-
|
42
|
-
|
17
|
+
let(:exec_method) do
|
18
|
+
::ActiveRecord::VERSION::STRING.start_with?('3.1.') ? :to_a : :exec_queries
|
19
|
+
end
|
43
20
|
|
44
|
-
|
45
|
-
|
46
|
-
end
|
21
|
+
let(:relation) do
|
22
|
+
mock_relation = mock(:relation, loaded?: false, select_values: [], hydra_select_values: [])
|
47
23
|
|
48
|
-
|
49
|
-
|
50
|
-
|
24
|
+
mock_relation.stub(exec_method).and_return(records)
|
25
|
+
mock_relation.stub(:klass).and_return(records.first.class)
|
26
|
+
mock_relation.stub(:where).and_return(mock_relation)
|
27
|
+
mock_relation
|
28
|
+
end
|
51
29
|
|
52
|
-
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
30
|
+
let(:records) do
|
31
|
+
[record]
|
56
32
|
end
|
57
33
|
|
58
|
-
|
59
|
-
|
60
|
-
|
34
|
+
before do
|
35
|
+
relation.singleton_class.send(:include, HydraAttribute::ActiveRecord::Relation)
|
36
|
+
end
|
61
37
|
|
62
|
-
describe "
|
38
|
+
describe "#exec_queries" do
|
63
39
|
describe 'parent method return one record' do
|
64
40
|
it 'should return one record' do
|
65
|
-
|
41
|
+
relation.send(exec_method).should have(1).record
|
66
42
|
end
|
67
43
|
end
|
68
44
|
|
69
45
|
describe 'parent method returns two records' do
|
70
|
-
let(:records) { [record_class(loaded_associations).new, record_class(loaded_associations).new] }
|
71
|
-
|
72
46
|
describe 'association models are already loaded' do
|
73
|
-
let(:
|
47
|
+
let(:records) { [loaded_record, loaded_record] }
|
74
48
|
|
75
49
|
it 'should return two record' do
|
76
|
-
|
50
|
+
relation.send(exec_method).should have(2).records
|
77
51
|
end
|
78
52
|
end
|
79
53
|
|
80
54
|
describe 'association models are not yet loaded' do
|
81
|
-
let(:
|
55
|
+
let(:records) { [record, record] }
|
82
56
|
|
83
57
|
before do
|
84
58
|
::ActiveRecord::Associations::Preloader.should_receive(:new).with(records, :hydra_string_attributes).and_return(mock(run: records))
|
85
59
|
end
|
86
60
|
|
87
61
|
it 'should return two record' do
|
88
|
-
|
62
|
+
relation.send(exec_method).should have(2).records
|
89
63
|
end
|
90
64
|
end
|
91
65
|
end
|
@@ -3,9 +3,13 @@ require 'spec_helper'
|
|
3
3
|
describe HydraAttribute::ActiveRecord::Scoping do
|
4
4
|
describe '#scoped' do
|
5
5
|
let(:ancestor) do
|
6
|
+
method = ::ActiveRecord::VERSION::STRING.starts_with?('3.1.') ? :to_a : :exec_queries
|
7
|
+
instance = mock(:instance_relation, where: nil, method => nil)
|
8
|
+
|
6
9
|
Module.new do
|
7
|
-
|
8
|
-
|
10
|
+
define_method :scoped do |*|
|
11
|
+
instance
|
12
|
+
end
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
@@ -62,35 +62,4 @@ describe HydraAttribute::Configuration do
|
|
62
62
|
config.associated_const_name(:string).should == :StringAttribute
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
66
|
-
describe '#relation_execute_method' do
|
67
|
-
after do
|
68
|
-
::ActiveRecord::VERSION.send(:remove_const, :MINOR)
|
69
|
-
::ActiveRecord::VERSION.const_set(:MINOR, @old_value)
|
70
|
-
end
|
71
|
-
|
72
|
-
describe 'ActiveRecord::VERSION::MINOR is great than 1' do
|
73
|
-
before do
|
74
|
-
@old_value = ::ActiveRecord::VERSION::MINOR
|
75
|
-
::ActiveRecord::VERSION.send(:remove_const, :MINOR)
|
76
|
-
::ActiveRecord::VERSION.const_set(:MINOR, 2)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should return :exec_queries' do
|
80
|
-
config.relation_execute_method.should == :exec_queries
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'ActiveRecord::VERSION::MINOR is less than or equal 1' do
|
85
|
-
before do
|
86
|
-
@old_value = ::ActiveRecord::VERSION::MINOR
|
87
|
-
::ActiveRecord::VERSION.send(:remove_const, :MINOR)
|
88
|
-
::ActiveRecord::VERSION.const_set(:MINOR, 1)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should return :to_a' do
|
92
|
-
config.relation_execute_method.should == :to_a
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hydra_attribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-12 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &2151761260 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2151761260
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2151759920 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2151759920
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &2151757300 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2151757300
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &2151755780 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2151755780
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: database_cleaner
|
60
|
-
requirement: &
|
60
|
+
requirement: &2151753880 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2151753880
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: appraisal
|
71
|
-
requirement: &
|
71
|
+
requirement: &2151747420 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2151747420
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rake
|
82
|
-
requirement: &
|
82
|
+
requirement: &2151746260 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2151746260
|
91
91
|
description: hydra_attribute is an implementation of EAV pattern for ActiveRecord
|
92
92
|
models.
|
93
93
|
email: kostya.stepanyuk@gmail.com
|
@@ -107,16 +107,18 @@ files:
|
|
107
107
|
- features/attribute_methods.feature
|
108
108
|
- features/define_attributes.feature
|
109
109
|
- features/load_associations.feature
|
110
|
-
- features/
|
111
|
-
- features/
|
110
|
+
- features/query_methods/group.feature
|
111
|
+
- features/query_methods/order.feature
|
112
|
+
- features/query_methods/select.feature
|
113
|
+
- features/query_methods/where.feature
|
112
114
|
- features/step_definitions/class_steps.rb
|
113
115
|
- features/step_definitions/model_steps.rb
|
116
|
+
- features/step_definitions/query_methods.rb
|
114
117
|
- features/step_definitions/record_steps.rb
|
115
118
|
- features/support/env.rb
|
116
119
|
- features/support/schema.rb
|
117
120
|
- features/support/world.rb
|
118
121
|
- features/typecast_attributes.feature
|
119
|
-
- features/where_conditions.feature
|
120
122
|
- gemfiles/3.1.gemfile
|
121
123
|
- gemfiles/3.1.gemfile.lock
|
122
124
|
- gemfiles/3.2.gemfile
|
@@ -170,6 +172,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
172
|
- - ! '>='
|
171
173
|
- !ruby/object:Gem::Version
|
172
174
|
version: '0'
|
175
|
+
segments:
|
176
|
+
- 0
|
177
|
+
hash: -33625434151420815
|
173
178
|
requirements: []
|
174
179
|
rubyforge_project:
|
175
180
|
rubygems_version: 1.8.10
|
@@ -181,16 +186,18 @@ test_files:
|
|
181
186
|
- features/attribute_methods.feature
|
182
187
|
- features/define_attributes.feature
|
183
188
|
- features/load_associations.feature
|
184
|
-
- features/
|
185
|
-
- features/
|
189
|
+
- features/query_methods/group.feature
|
190
|
+
- features/query_methods/order.feature
|
191
|
+
- features/query_methods/select.feature
|
192
|
+
- features/query_methods/where.feature
|
186
193
|
- features/step_definitions/class_steps.rb
|
187
194
|
- features/step_definitions/model_steps.rb
|
195
|
+
- features/step_definitions/query_methods.rb
|
188
196
|
- features/step_definitions/record_steps.rb
|
189
197
|
- features/support/env.rb
|
190
198
|
- features/support/schema.rb
|
191
199
|
- features/support/world.rb
|
192
200
|
- features/typecast_attributes.feature
|
193
|
-
- features/where_conditions.feature
|
194
201
|
- gemfiles/3.1.gemfile
|
195
202
|
- gemfiles/3.1.gemfile.lock
|
196
203
|
- gemfiles/3.2.gemfile
|