hydra_attribute 0.4.1 → 0.4.2

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.
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ tmp
18
18
  .idea
19
19
  .rvmrc
20
20
  bin/
21
+ gemfiles
data/.travis.yml CHANGED
@@ -2,6 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
 
5
+ before_install: bundle && rake appraisal:gemfiles
6
+
5
7
  gemfile:
6
8
  - gemfiles/3.1.gemfile
7
9
  - gemfiles/3.2.gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
+ **0.4.2 (January 20, 2013)**
2
+ * Fixed bug in `count` method which added unnecessary columns to query [#2](https://github.com/kostyantyn/hydra_attribute/issues/2)
3
+
1
4
  **0.4.1 (October 3, 2012)**
2
- * Fixed bug which din't allow to use hydra attributes for STI models
5
+ * Fixed bug which didn't allow to use hydra attributes for STI models
3
6
 
4
7
  **0.4.0 (September 13, 2012)**
5
8
  * Add attribute sets
@@ -49,4 +52,4 @@
49
52
  * Implement `where` method for `ActiveRecord::Relation` object
50
53
  * Implement `order` method for `ActiveRecord::Relation` object
51
54
  * Implement `reverse_order` method for `ActiveRecord::Relation` object
52
- * Implement `select` method for `ActiveRecord::Relation` object
55
+ * Implement `select` method for `ActiveRecord::Relation` object
data/README.md CHANGED
@@ -1,13 +1,18 @@
1
- # hydra_attribute [![Build Status](https://secure.travis-ci.org/kostyantyn/hydra_attribute.png)](http://travis-ci.org/kostyantyn/hydra_attribute)
1
+ # hydra_attribute [![Gem Version](https://fury-badge.herokuapp.com/rb/hydra_attribute.png)](http://badge.fury.io/rb/hydra_attribute) [![Build Status](https://secure.travis-ci.org/kostyantyn/hydra_attribute.png)](http://travis-ci.org/kostyantyn/hydra_attribute)
2
2
 
3
3
  [Wiki](https://github.com/kostyantyn/hydra_attribute/wiki) | [RDoc](http://rdoc.info/github/kostyantyn/hydra_attribute)
4
4
 
5
5
  hydra_attribute is an implementation of
6
6
  [EAV (Entity-Attribute-Value) pattern](http://en.wikipedia.org/wiki/Entity–attribute–value_model) for ActiveRecord models. It allows to create or remove attributes in runtime. Also each record may have different sets of attributes, for example: Product with ID 1 can have different set of attributes than Product with ID 2.
7
7
 
8
+ ## Notice
9
+ Until the first major version is released:
10
+ * each new minor version doesn't guarantee back compatibility with previous one
11
+ * gem isn't stable enough for using in production
12
+
8
13
  ## Requirements
9
14
  * ruby >= 1.9.2
10
- * active_record >= 3.1
15
+ * active_record ~> 3.1
11
16
 
12
17
  ## Installation
13
18
 
@@ -162,10 +167,6 @@ Product.group(:color).count
162
167
  * [Helper methods](https://github.com/kostyantyn/hydra_attribute/wiki/Helper-methods)
163
168
  * [Migrate from 0.3.2 to 0.4.0](https://github.com/kostyantyn/hydra_attribute/wiki/Migrate-from-0.3.2-to-0.4.0)
164
169
 
165
- ## Notice
166
-
167
- The each new minor version doesn't guarantee back compatibility with previous one until the first major version is released.
168
-
169
170
  ## Contributing
170
171
 
171
172
  1. Fork it
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
15
15
  gem.version = HydraAttribute::VERSION
16
16
 
17
- gem.add_dependency('activerecord', '>= 3.1.0')
17
+ gem.add_dependency('activerecord', '~> 3.1')
18
18
 
19
19
  gem.add_development_dependency('rspec')
20
20
  gem.add_development_dependency('cucumber')
@@ -22,4 +22,4 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency('database_cleaner')
23
23
  gem.add_development_dependency('appraisal')
24
24
  gem.add_development_dependency('rake')
25
- end
25
+ end
@@ -33,6 +33,7 @@ require 'hydra_attribute/active_record/association'
33
33
  require 'hydra_attribute/active_record/association_preloader'
34
34
  require 'hydra_attribute/active_record/migration'
35
35
  require 'hydra_attribute/active_record/relation'
36
+ require 'hydra_attribute/active_record/relation/calculations'
36
37
  require 'hydra_attribute/active_record/relation/query_methods'
37
38
  require 'hydra_attribute/active_record/attribute_methods'
38
39
 
@@ -4,6 +4,7 @@ module HydraAttribute
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
+ include Calculation
7
8
  include QueryMethods
8
9
 
9
10
  # @COMPATIBILITY with 3.1.x active_record 3.1 doesn't have "exec_queries" method
@@ -0,0 +1,19 @@
1
+ module HydraAttribute
2
+ module ActiveRecord
3
+ module Relation
4
+ module Calculation
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :hydra_attribute_performs_calculation
9
+ end
10
+
11
+ # Notifies +#build_arel+ method that it builds query for calculation
12
+ def execute_simple_calculation(operation, column_name, distinct)
13
+ self.hydra_attribute_performs_calculation = true
14
+ super(operation, column_name, distinct)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -53,8 +53,10 @@ module HydraAttribute
53
53
  @hydra_select_values.map!(&:to_s)
54
54
  @select_values.map!{ |value| hydra_helper.prepend_table_name(value) }
55
55
 
56
- # attributes "id" and "hydra_set_id" are important for hydra_attribute gem
57
- if @hydra_select_values.any? or @select_values.any?
56
+ # attributes "id" and "hydra_set_id" are required for models which use HydraAttribute::ActiveRecord model
57
+ # but if calculation method is performed, obtained data from database aren't converted to models
58
+ # so these attributes should not be forcibly added to query
59
+ if !hydra_attribute_performs_calculation && (@hydra_select_values.any? or @select_values.any?)
58
60
  @select_values << hydra_helper.prepend_table_name(klass.primary_key)
59
61
  @select_values << hydra_helper.prepend_table_name('hydra_set_id')
60
62
  end
@@ -1,3 +1,3 @@
1
1
  module HydraAttribute
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe HydraAttribute::ActiveRecord::Relation::QueryMethods do
4
+ describe '#build_arel' do
5
+ describe 'necessary columns for hydra attribute' do
6
+ let(:id_column) { Product.quoted_table_name + '.' + Product.quoted_primary_key }
7
+ let(:hydra_set_id_column) { Product.quoted_table_name + '.' + Product.quoted_primary_key }
8
+
9
+ it 'should add "id" and "hydra_set_id" columns to query if they are omitted' do
10
+ arel = Product.select(:name).build_arel
11
+ arel.to_sql.should match(id_column)
12
+ arel.to_sql.should match(hydra_set_id_column)
13
+ end
14
+
15
+ it 'should not add "id" and "hydra_set_id" columns to default query' do
16
+ arel = Product.scoped.build_arel
17
+ arel.to_sql.should_not match(id_column)
18
+ arel.to_sql.should_not match(hydra_set_id_column)
19
+ end
20
+
21
+ it 'should not add "id" and "hydra_set_id" columns to query which performs calculation' do
22
+ scope = Product.select(:name)
23
+ scope.hydra_attribute_performs_calculation = true
24
+
25
+ arel = scope.build_arel
26
+ arel.to_sql.should_not match(id_column)
27
+ arel.to_sql.should_not match(hydra_set_id_column)
28
+ end
29
+ end
30
+ end
31
+ 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.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2013-01-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 3.1.0
21
+ version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ! '>='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 3.1.0
29
+ version: '3.1'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -162,10 +162,6 @@ files:
162
162
  - features/step_definitions/record_steps.rb
163
163
  - features/support/env.rb
164
164
  - features/support/world.rb
165
- - gemfiles/3.1.gemfile
166
- - gemfiles/3.1.gemfile.lock
167
- - gemfiles/3.2.gemfile
168
- - gemfiles/3.2.gemfile.lock
169
165
  - hydra_attribute.gemspec
170
166
  - lib/hydra_attribute.rb
171
167
  - lib/hydra_attribute/active_record.rb
@@ -175,6 +171,7 @@ files:
175
171
  - lib/hydra_attribute/active_record/migration.rb
176
172
  - lib/hydra_attribute/active_record/reflection.rb
177
173
  - lib/hydra_attribute/active_record/relation.rb
174
+ - lib/hydra_attribute/active_record/relation/calculations.rb
178
175
  - lib/hydra_attribute/active_record/relation/query_methods.rb
179
176
  - lib/hydra_attribute/active_record/scoping.rb
180
177
  - lib/hydra_attribute/association_builder.rb
@@ -195,6 +192,7 @@ files:
195
192
  - lib/rails/generators/hydra_attribute/install/install_generator.rb
196
193
  - lib/rails/generators/hydra_attribute/install/templates/hydra_attribute.txt
197
194
  - spec/hydra_attribute/active_record/attribute_methods_spec.rb
195
+ - spec/hydra_attribute/active_record/relation/query_methods_spec.rb
198
196
  - spec/hydra_attribute/hydra_attribute_methods_spec.rb
199
197
  - spec/hydra_attribute/hydra_attribute_spec.rb
200
198
  - spec/hydra_attribute/hydra_methods_spec.rb
@@ -222,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
220
  version: '0'
223
221
  segments:
224
222
  - 0
225
- hash: -3857802354378024215
223
+ hash: -595006172525400845
226
224
  requirements: []
227
225
  rubyforge_project:
228
226
  rubygems_version: 1.8.24
@@ -253,11 +251,8 @@ test_files:
253
251
  - features/step_definitions/record_steps.rb
254
252
  - features/support/env.rb
255
253
  - features/support/world.rb
256
- - gemfiles/3.1.gemfile
257
- - gemfiles/3.1.gemfile.lock
258
- - gemfiles/3.2.gemfile
259
- - gemfiles/3.2.gemfile.lock
260
254
  - spec/hydra_attribute/active_record/attribute_methods_spec.rb
255
+ - spec/hydra_attribute/active_record/relation/query_methods_spec.rb
261
256
  - spec/hydra_attribute/hydra_attribute_methods_spec.rb
262
257
  - spec/hydra_attribute/hydra_attribute_spec.rb
263
258
  - spec/hydra_attribute/hydra_methods_spec.rb
data/gemfiles/3.1.gemfile DELETED
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "activerecord", "~> 3.1.0"
6
-
7
- gemspec :path=>"../"
@@ -1,61 +0,0 @@
1
- PATH
2
- remote: /Users/kostyantyn/Sites/github/gems/hydra_attribute
3
- specs:
4
- hydra_attribute (0.4.1)
5
- activerecord (>= 3.1.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.1.8)
11
- activesupport (= 3.1.8)
12
- builder (~> 3.0.0)
13
- i18n (~> 0.6)
14
- activerecord (3.1.8)
15
- activemodel (= 3.1.8)
16
- activesupport (= 3.1.8)
17
- arel (~> 2.2.3)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.1.8)
20
- multi_json (>= 1.0, < 1.3)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (2.2.3)
25
- builder (3.0.3)
26
- cucumber (1.2.1)
27
- builder (>= 2.1.2)
28
- diff-lcs (>= 1.1.3)
29
- gherkin (~> 2.11.0)
30
- json (>= 1.4.6)
31
- database_cleaner (0.8.0)
32
- diff-lcs (1.1.3)
33
- gherkin (2.11.2)
34
- json (>= 1.4.6)
35
- i18n (0.6.1)
36
- json (1.7.5)
37
- multi_json (1.2.0)
38
- rake (0.9.2.2)
39
- rspec (2.11.0)
40
- rspec-core (~> 2.11.0)
41
- rspec-expectations (~> 2.11.0)
42
- rspec-mocks (~> 2.11.0)
43
- rspec-core (2.11.1)
44
- rspec-expectations (2.11.3)
45
- diff-lcs (~> 1.1.3)
46
- rspec-mocks (2.11.2)
47
- sqlite3 (1.3.6)
48
- tzinfo (0.3.33)
49
-
50
- PLATFORMS
51
- ruby
52
-
53
- DEPENDENCIES
54
- activerecord (~> 3.1.0)
55
- appraisal
56
- cucumber
57
- database_cleaner
58
- hydra_attribute!
59
- rake
60
- rspec
61
- sqlite3
data/gemfiles/3.2.gemfile DELETED
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source :rubygems
4
-
5
- gem "activerecord", "~> 3.2.0"
6
-
7
- gemspec :path=>"../"
@@ -1,61 +0,0 @@
1
- PATH
2
- remote: /Users/kostyantyn/Sites/github/gems/hydra_attribute
3
- specs:
4
- hydra_attribute (0.4.1)
5
- activerecord (>= 3.1.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.2.8)
11
- activesupport (= 3.2.8)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.8)
14
- activemodel (= 3.2.8)
15
- activesupport (= 3.2.8)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.8)
19
- i18n (~> 0.6)
20
- multi_json (~> 1.0)
21
- appraisal (0.4.1)
22
- bundler
23
- rake
24
- arel (3.0.2)
25
- builder (3.0.3)
26
- cucumber (1.2.1)
27
- builder (>= 2.1.2)
28
- diff-lcs (>= 1.1.3)
29
- gherkin (~> 2.11.0)
30
- json (>= 1.4.6)
31
- database_cleaner (0.8.0)
32
- diff-lcs (1.1.3)
33
- gherkin (2.11.2)
34
- json (>= 1.4.6)
35
- i18n (0.6.1)
36
- json (1.7.5)
37
- multi_json (1.3.6)
38
- rake (0.9.2.2)
39
- rspec (2.11.0)
40
- rspec-core (~> 2.11.0)
41
- rspec-expectations (~> 2.11.0)
42
- rspec-mocks (~> 2.11.0)
43
- rspec-core (2.11.1)
44
- rspec-expectations (2.11.3)
45
- diff-lcs (~> 1.1.3)
46
- rspec-mocks (2.11.2)
47
- sqlite3 (1.3.6)
48
- tzinfo (0.3.33)
49
-
50
- PLATFORMS
51
- ruby
52
-
53
- DEPENDENCIES
54
- activerecord (~> 3.2.0)
55
- appraisal
56
- cucumber
57
- database_cleaner
58
- hydra_attribute!
59
- rake
60
- rspec
61
- sqlite3