hstore_accessor 0.9.1 → 0.9.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: 30975fed8d563ae146155f5dd5a4ebe4b0abb861
4
- data.tar.gz: ba2bff2e3e25eee710c564b153bf61c05d07a44f
3
+ metadata.gz: 592e1d4cc9607136333c47a39aecafc5591c81b0
4
+ data.tar.gz: c5c93b8c441dfea93d0f61c030f58b0f4f1caf7c
5
5
  SHA512:
6
- metadata.gz: ad3a0009ff1771d4feddb626e3eb4e4a737b3a0c2394e6b0fd5844f12e23aded98d9dd71c57f7dd96d6a3b00a7e93f6e4fd367f90bb744e2c02af2eea2bd679c
7
- data.tar.gz: 5d09fc9d042e67a6e03bdbf377e8242b9e307a64ae66aaf0d4c48b395cb72d3f0511a6cf8f13ff2a82fb753926c65328b609916a1ccbb6792660060d936ab8a1
6
+ metadata.gz: c27f4b979405b4c6fbe1aa67de3a3ed0924460daaed0d5002bc5ea320171dc3c448aae24940f90a8a3fdb909e16d48422e7871ca450f017734953cc70b291f94
7
+ data.tar.gz: f46afee55e0b917c7e24cdb8a092594502efe177169ff5f06324c6b6ad74b570002be99aaf23a24d0af1a6bcdb86715acff10f83eca1a55b56ffb243e7cca52f
@@ -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 = "0.9.1"
2
+ VERSION = "0.9.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" },
@@ -11,6 +12,7 @@ FIELDS = {
11
12
  tags: :array,
12
13
  reviews: :hash,
13
14
  released_at: :date,
15
+ likes: :integer,
14
16
  miles: :decimal
15
17
  }
16
18
 
@@ -18,9 +20,15 @@ DATA_FIELDS = {
18
20
  color_data: :string
19
21
  }
20
22
 
23
+ class ProductCategory < ActiveRecord::Base
24
+ hstore_accessor :options, name: :string, likes: :integer
25
+ has_many :products
26
+ end
27
+
21
28
  class Product < ActiveRecord::Base
22
29
  hstore_accessor :options, FIELDS
23
30
  hstore_accessor :data, DATA_FIELDS
31
+ belongs_to :product_category
24
32
  end
25
33
 
26
34
  class SuperProduct < Product
@@ -147,10 +155,35 @@ describe HstoreAccessor do
147
155
  describe "scopes" do
148
156
  let!(:timestamp) { Time.now }
149
157
  let!(:datestamp) { Date.today }
150
- let!(:product_a) { Product.create(color: "green", price: 10, weight: 10.1, tags: %w(tag1 tag2 tag3), popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal.new("10.113379001")) }
158
+ let!(:product_a) { Product.create(likes: 3, name: "widget", color: "green", price: 10, weight: 10.1, tags: %w(tag1 tag2 tag3), popular: true, build_timestamp: (timestamp - 10.days), released_at: (datestamp - 8.days), miles: BigDecimal.new("10.113379001")) }
151
159
  let!(:product_b) { Product.create(color: "orange", price: 20, weight: 20.2, tags: %w(tag2 tag3 tag4), popular: false, build_timestamp: (timestamp - 5.days), released_at: (datestamp - 4.days), miles: BigDecimal.new("20.213379001")) }
152
160
  let!(:product_c) { Product.create(color: "blue", price: 30, weight: 30.3, tags: %w(tag3 tag4 tag5), popular: true, build_timestamp: timestamp, released_at: datestamp, miles: BigDecimal.new("30.313379001")) }
153
161
 
162
+ context "ambiguous column names" do
163
+ let!(:product_category) { ProductCategory.create!(name: "widget", likes: 2) }
164
+
165
+ before do
166
+ product_category.products = Product.all
167
+ product_category.save!
168
+ end
169
+
170
+ context "eq query" do
171
+ let!(:query) { Product.all.joins(:product_category).merge(ProductCategory.with_name("widget")).with_name("widget") }
172
+
173
+ it "qualifies the table name to prevent ambiguous column name references" do
174
+ expect { query.to_a }.to_not raise_error
175
+ end
176
+ end
177
+
178
+ context "query" do
179
+ let!(:query) { Product.all.joins(:product_category).merge(ProductCategory.likes_lt(4)).likes_lt(4) }
180
+
181
+ it "qualifies the table name to prevent ambiguous column name references" do
182
+ expect { query.to_a }.to_not raise_error
183
+ end
184
+ end
185
+ end
186
+
154
187
  context "for string fields support" do
155
188
  it "equality" do
156
189
  expect(Product.with_color("orange").to_a).to eq [product_b]
data/spec/spec_helper.rb CHANGED
@@ -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
@@ -42,4 +44,8 @@ def create_database
42
44
  t.decimal :decimal_type
43
45
  t.hstore :hash_type
44
46
  end
47
+
48
+ ActiveRecord::Base.connection.create_table(:product_categories) do |t|
49
+ t.hstore :options
50
+ end
45
51
  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: 0.9.1
4
+ version: 0.9.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