hydra_attribute 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,11 +1,30 @@
1
+ **0.1.3 (June 11, 2012)**
2
+ * Fix bug when quoted column is passed to `ActiveRecord::Relation` method as a parameter
3
+
1
4
  **0.1.2 (June 7, 2012)**
2
- * eval define_hydra_attributes block in Builder scope
5
+ * Eval `define_hydra_attributes` block in Builder scope
6
+
7
+ ```ruby
8
+ define_hydra_attributes do
9
+ string :name
10
+ float :price
11
+ end
12
+ ```
3
13
 
4
14
  **0.1.1 (June 6, 2012)**
15
+ * Update gem specification
5
16
 
6
17
  **0.1.0 (June 6, 2012)** (initial release)
7
- * define EAV attributes
8
- * "where" condition
9
- * "order" condition
10
- * "reverse_order" condition
11
- * "select" condition
18
+ * Define EAV attributes
19
+
20
+ ```ruby
21
+ define_hydra_attributes do |hydra|
22
+ hydra.string :name
23
+ hydra.float :price
24
+ end
25
+ ```
26
+
27
+ * Implement `where` method for `ActiveRecord::Relation` object
28
+ * Implement `order` method for `ActiveRecord::Relation` object
29
+ * Implement `reverse_order` method for `ActiveRecord::Relation` object
30
+ * Implement `select` method for `ActiveRecord::Relation` object
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kostyantyn/Sites/github/gems/hydra_attribute
3
3
  specs:
4
- hydra_attribute (0.1.2.beta1)
4
+ hydra_attribute (0.1.3.beta1)
5
5
  activerecord (>= 3.1.0)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kostyantyn/Sites/github/gems/hydra_attribute
3
3
  specs:
4
- hydra_attribute (0.1.2.beta1)
4
+ hydra_attribute (0.1.3.beta1)
5
5
  activerecord (>= 3.1.0)
6
6
 
7
7
  GEM
@@ -77,13 +77,11 @@ module HydraAttribute
77
77
  end
78
78
 
79
79
  def prepend_table_name(column)
80
- case column
81
- when Symbol, String
82
- if column.to_s.include?('.') or column.to_s.include?(')')
83
- column
84
- else
85
- klass.quoted_table_name + '.' + connection.quote_column_name(column.to_s)
86
- end
80
+ return column unless column.is_a?(Symbol) or column.is_a?(String)
81
+
82
+ copy = column.to_s.strip
83
+ if copy =~ /^\w+$/
84
+ klass.quoted_table_name + '.' + connection.quote_column_name(copy)
87
85
  else
88
86
  column
89
87
  end
@@ -1,3 +1,3 @@
1
1
  module HydraAttribute
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -283,4 +283,52 @@ describe HydraAttribute::ActiveRecord::Relation::QueryMethods do
283
283
  end
284
284
  end
285
285
  end
286
+ end
287
+
288
+ describe HydraAttribute::ActiveRecord::Relation::QueryMethods::Helper do
289
+ let(:relation_class) do
290
+ mock(table_name: 'entities', quoted_table_name: '"entities"')
291
+ end
292
+
293
+ let(:connection) do
294
+ mock_connection = mock
295
+ mock_connection.stub(:quote_column_name) { |column| %Q("#{column}") }
296
+ mock_connection
297
+ end
298
+
299
+ let(:relation) do
300
+ mock(klass: relation_class, connection: connection)
301
+ end
302
+
303
+ let(:helper) do
304
+ HydraAttribute::ActiveRecord::Relation::QueryMethods::Helper.new(relation)
305
+ end
306
+
307
+ describe '#prepend_table_name' do
308
+ describe 'param is Symbol' do
309
+ it 'should prepend table name and quote param' do
310
+ helper.prepend_table_name(:column).should == '"entities"."column"'
311
+ end
312
+ end
313
+
314
+ describe 'param is String' do
315
+ describe 'params is a word character (letter, number, underscore)' do
316
+ it 'should prepend table name and quote param' do
317
+ helper.prepend_table_name('abc').should == '"entities"."abc"'
318
+ helper.prepend_table_name('a_c').should == '"entities"."a_c"'
319
+ helper.prepend_table_name('a1c').should == '"entities"."a1c"'
320
+ helper.prepend_table_name(' a ').should == '"entities"."a"'
321
+ end
322
+ end
323
+
324
+ describe 'params is not a word character (letter, number, underscore)' do
325
+ it 'should return current string' do
326
+ helper.prepend_table_name('a c').should == 'a c'
327
+ helper.prepend_table_name('a-c').should == 'a-c'
328
+ helper.prepend_table_name('(a)').should == '(a)'
329
+ helper.prepend_table_name('.').should == '.'
330
+ end
331
+ end
332
+ end
333
+ end
286
334
  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.1.2
4
+ version: 0.1.3
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-07 00:00:00.000000000Z
12
+ date: 2012-06-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &2152687640 !ruby/object:Gem::Requirement
16
+ requirement: &2153039400 !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: *2152687640
24
+ version_requirements: *2153039400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2152687240 !ruby/object:Gem::Requirement
27
+ requirement: &2153032420 !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: *2152687240
35
+ version_requirements: *2153032420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: cucumber
38
- requirement: &2152686780 !ruby/object:Gem::Requirement
38
+ requirement: &2153031960 !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: *2152686780
46
+ version_requirements: *2153031960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &2152686340 !ruby/object:Gem::Requirement
49
+ requirement: &2153031540 !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: *2152686340
57
+ version_requirements: *2153031540
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: database_cleaner
60
- requirement: &2152685920 !ruby/object:Gem::Requirement
60
+ requirement: &2153031120 !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: *2152685920
68
+ version_requirements: *2153031120
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: appraisal
71
- requirement: &2152685500 !ruby/object:Gem::Requirement
71
+ requirement: &2153030700 !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: *2152685500
79
+ version_requirements: *2153030700
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rake
82
- requirement: &2152685080 !ruby/object:Gem::Requirement
82
+ requirement: &2153030280 !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: *2152685080
90
+ version_requirements: *2153030280
91
91
  description: hydra_attribute is an implementation of EAV pattern for ActiveRecord
92
92
  models.
93
93
  email: kostya.stepanyuk@gmail.com