hstore_accessor 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: adf6ed0370312b664c3fa65a0b95662a039e3360
4
- data.tar.gz: 49ade9c932fa9a56860522a19479c21ae8cb1b0b
3
+ metadata.gz: 5a802c392aa44501909aca2592be40d690f047ae
4
+ data.tar.gz: 3a6c54bc24ba9d4202fe8d17331f9958a66fb752
5
5
  SHA512:
6
- metadata.gz: 69e70ea61aeb26354ec2386aa12f38a32f480b62a6c70953a0dffc338f9bd0d4eb1d164926723a342b0b432868086169f8f681739db54e1105e42ed30b653908
7
- data.tar.gz: 27e43ef6addfd779c2f3515899654ea53a181f96f2e993224a0db2de11cefa30ae0354d288a9d1cecdd7c1fe1461cdf8d80c96735c2b0a78c8e696324b892389
6
+ metadata.gz: 6e29122e812fa3097e773f8e6a81116d7b9809975406ba91d6b6c5a2dcda399678db3cce6d3ec6e75cfb3acd0479ff9ab71f03ed9fd61825e0cb19afc3e5fe6b
7
+ data.tar.gz: 8b6cc7c1d1bf7bcdcfd52c7f158b283782f8a722c1607538c5c0d40645ae2af7f230bd5d745d1427ffb28703dbf81bf53407a3f3b405cf113a65fecc5d1b9795
@@ -23,6 +23,8 @@ Style/AlignParameters:
23
23
  Enabled: false
24
24
  Style/ClassAndModuleChildren:
25
25
  Enabled: false
26
+ Style/ClassVars:
27
+ Enabled: false
26
28
  Style/Documentation:
27
29
  Enabled: false
28
30
  Style/FileName:
@@ -115,8 +115,8 @@ module HstoreAccessor
115
115
  end
116
116
  end
117
117
 
118
- query_field = "#{hstore_attribute} -> '#{store_key}'"
119
- eq_query_field = "#{hstore_attribute} @> hstore('#{store_key}', ?)"
118
+ query_field = "#{table_name}.#{hstore_attribute} -> '#{store_key}'"
119
+ eq_query_field = "#{table_name}.#{hstore_attribute} @> hstore('#{store_key}', ?)"
120
120
 
121
121
  case data_type
122
122
  when :string
@@ -1,3 +1,3 @@
1
1
  module HstoreAccessor
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -2,6 +2,7 @@ require "spec_helper"
2
2
  require "active_support/all"
3
3
 
4
4
  FIELDS = {
5
+ name: :string,
5
6
  color: :string,
6
7
  price: :integer,
7
8
  published: { data_type: :boolean, store_key: "p" },
@@ -9,6 +10,7 @@ FIELDS = {
9
10
  popular: :boolean,
10
11
  build_timestamp: :datetime,
11
12
  released_at: :date,
13
+ likes: :integer,
12
14
  miles: :decimal
13
15
  }
14
16
 
@@ -16,9 +18,15 @@ DATA_FIELDS = {
16
18
  color_data: :string
17
19
  }
18
20
 
21
+ class ProductCategory < ActiveRecord::Base
22
+ hstore_accessor :options, name: :string, likes: :integer
23
+ has_many :products
24
+ end
25
+
19
26
  class Product < ActiveRecord::Base
20
27
  hstore_accessor :options, FIELDS
21
28
  hstore_accessor :data, DATA_FIELDS
29
+ belongs_to :product_category
22
30
  end
23
31
 
24
32
  class SuperProduct < Product
@@ -145,10 +153,35 @@ describe HstoreAccessor do
145
153
  describe "scopes" do
146
154
  let!(:timestamp) { Time.now }
147
155
  let!(:datestamp) { Date.today }
148
- let!(:product_a) { Product.create(color: "green", price: 10, weight: 10.1, popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal.new("10.113379001")) }
156
+ let!(:product_a) { Product.create(likes: 3, name: "widget", color: "green", price: 10, weight: 10.1, popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal.new("10.113379001")) }
149
157
  let!(:product_b) { Product.create(color: "orange", price: 20, weight: 20.2, popular: false, build_timestamp: (timestamp - 5.days), released_at: (datestamp - 4.days), miles: BigDecimal.new("20.213379001")) }
150
158
  let!(:product_c) { Product.create(color: "blue", price: 30, weight: 30.3, popular: true, build_timestamp: timestamp, released_at: datestamp, miles: BigDecimal.new("30.313379001")) }
151
159
 
160
+ context "ambiguous column names" do
161
+ let!(:product_category) { ProductCategory.create!(name: "widget", likes: 2) }
162
+
163
+ before do
164
+ product_category.products = Product.all
165
+ product_category.save!
166
+ end
167
+
168
+ context "eq query" do
169
+ let!(:query) { Product.all.joins(:product_category).merge(ProductCategory.with_name("widget")).with_name("widget") }
170
+
171
+ it "qualifies the table name to prevent ambiguous column name references" do
172
+ expect { query.to_a }.to_not raise_error
173
+ end
174
+ end
175
+
176
+ context "query" do
177
+ let!(:query) { Product.all.joins(:product_category).merge(ProductCategory.likes_lt(4)).likes_lt(4) }
178
+
179
+ it "qualifies the table name to prevent ambiguous column name references" do
180
+ expect { query.to_a }.to_not raise_error
181
+ end
182
+ end
183
+ end
184
+
152
185
  context "for string fields support" do
153
186
  it "equality" do
154
187
  expect(Product.with_color("orange").to_a).to eq [product_b]
@@ -26,6 +26,7 @@ def create_database
26
26
 
27
27
  ActiveRecord::Base.connection.execute("CREATE EXTENSION hstore;") rescue ActiveRecord::StatementInvalid
28
28
  ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS products;")
29
+ ActiveRecord::Base.connection.execute("DROP TABLE IF EXISTS product_categories;")
29
30
 
30
31
  ActiveRecord::Base.connection.create_table(:products) do |t|
31
32
  t.hstore :options
@@ -33,6 +34,7 @@ def create_database
33
34
 
34
35
  t.string :string_type
35
36
  t.integer :integer_type
37
+ t.integer :product_category_id
36
38
  t.boolean :boolean_type
37
39
  t.float :float_type
38
40
  t.time :time_type
@@ -40,4 +42,8 @@ def create_database
40
42
  t.datetime :datetime_type
41
43
  t.decimal :decimal_type
42
44
  end
45
+
46
+ ActiveRecord::Base.connection.create_table(:product_categories) do |t|
47
+ t.hstore :options
48
+ end
43
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hstore_accessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Hirn
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-03-03 00:00:00.000000000 Z
15
+ date: 2015-03-16 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord