gigo-activerecord 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kencollins/Repositories/customink/gigo-activerecord
3
3
  specs:
4
- gigo-activerecord (1.1.0)
4
+ gigo-activerecord (1.2.0)
5
5
  activerecord (>= 3.0)
6
6
  gigo
7
7
 
@@ -28,7 +28,7 @@ GEM
28
28
  activesupport (>= 3.0)
29
29
  ensure_valid_encoding (~> 0.5.3)
30
30
  i18n (0.5.0)
31
- minitest (5.0.2)
31
+ minitest (5.0.4)
32
32
  rake (10.0.4)
33
33
  sqlite3 (1.3.7)
34
34
  tzinfo (0.3.37)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kencollins/Repositories/customink/gigo-activerecord
3
3
  specs:
4
- gigo-activerecord (1.1.0)
4
+ gigo-activerecord (1.2.0)
5
5
  activerecord (>= 3.0)
6
6
  gigo
7
7
 
@@ -29,8 +29,8 @@ GEM
29
29
  activesupport (>= 3.0)
30
30
  ensure_valid_encoding (~> 0.5.3)
31
31
  i18n (0.6.4)
32
- minitest (5.0.2)
33
- multi_json (1.7.3)
32
+ minitest (5.0.4)
33
+ multi_json (1.7.6)
34
34
  rake (10.0.4)
35
35
  sqlite3 (1.3.7)
36
36
  tzinfo (0.3.37)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kencollins/Repositories/customink/gigo-activerecord
3
3
  specs:
4
- gigo-activerecord (1.1.0)
4
+ gigo-activerecord (1.2.0)
5
5
  activerecord (>= 3.0)
6
6
  gigo
7
7
 
@@ -29,8 +29,8 @@ GEM
29
29
  activesupport (>= 3.0)
30
30
  ensure_valid_encoding (~> 0.5.3)
31
31
  i18n (0.6.1)
32
- minitest (5.0.2)
33
- multi_json (1.7.3)
32
+ minitest (5.0.4)
33
+ multi_json (1.7.6)
34
34
  rake (10.0.4)
35
35
  sqlite3 (1.3.7)
36
36
  tzinfo (0.3.37)
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: git://github.com/rails/rails.git
3
- revision: f47b4236e089b07cb683ee9b7ff8b06111a0ec10
3
+ revision: ebf2113a0565d2e38802f29291b3971b2c7f7922
4
4
  specs:
5
5
  activemodel (4.1.0.beta)
6
6
  activesupport (= 4.1.0.beta)
@@ -20,7 +20,7 @@ GIT
20
20
  PATH
21
21
  remote: /Users/kencollins/Repositories/customink/gigo-activerecord
22
22
  specs:
23
- gigo-activerecord (1.1.0)
23
+ gigo-activerecord (1.2.0)
24
24
  activerecord (>= 3.0)
25
25
  gigo
26
26
 
@@ -40,7 +40,7 @@ GEM
40
40
  ensure_valid_encoding (~> 0.5.3)
41
41
  i18n (0.6.4)
42
42
  json (1.8.0)
43
- minitest (5.0.2)
43
+ minitest (5.0.4)
44
44
  rake (10.0.4)
45
45
  sqlite3 (1.3.7)
46
46
  thread_safe (0.1.0)
@@ -17,7 +17,11 @@ module GIGO
17
17
  attrs.each do |attr|
18
18
  mod.module_eval <<-CODE, __FILE__, __LINE__
19
19
  def #{attr}
20
- GIGO.load(super)
20
+ begin
21
+ GIGO.load(super)
22
+ rescue NoMethodError, ActiveModel::MissingAttributeError
23
+ nil
24
+ end
21
25
  end
22
26
  CODE
23
27
  end
@@ -1,5 +1,5 @@
1
1
  module GIGO
2
2
  module ActiveRecord
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -41,14 +41,24 @@ module GIGO
41
41
 
42
42
  it 'allows serialized attribute to still work with nil/defaults' do
43
43
  user = UserGIGO.new
44
- user.notes.must_equal Hash.new
45
- user.save
46
- user.reload.notes.must_equal Hash.new
44
+ if activerecord_30?
45
+ user.notes.must_be_nil
46
+ user.save
47
+ user.reload.notes.must_be_nil
48
+ else
49
+ user.notes.must_equal Hash.new
50
+ user.save
51
+ user.reload.notes.must_equal Hash.new
52
+ end
47
53
  end
48
54
 
49
55
  it 'allows serialized attribute to still work as normal' do
50
56
  user = UserGIGO.new
51
- user.notes[:foo] = 'bar'
57
+ if activerecord_30?
58
+ user.notes = {:foo => 'bar'}
59
+ else
60
+ user.notes[:foo] = 'bar'
61
+ end
52
62
  user.save
53
63
  user.reload.notes[:foo].must_equal 'bar'
54
64
  end
@@ -59,14 +69,20 @@ module GIGO
59
69
 
60
70
  before { user_subject_binary }
61
71
 
62
- let(:id) { user_subject_binary.id }
72
+ let(:id) { user_subject_binary.id }
73
+ let(:user) { UserGIGO.find(id) }
74
+ let(:user_without_subject) { UserGIGOWithSuperSubject.find(id) }
63
75
 
64
76
  it 'hooks into GIGO' do
65
- UserGIGO.find(id).subject.must_equal "won’t"
77
+ user.subject.must_equal "won’t"
66
78
  end
67
79
 
68
80
  it 'allows user to further refine #subject method via super' do
69
- UserGIGOWithSuperSubject.find(id).subject.must_equal "WON’T"
81
+ user_without_subject.subject.must_equal "WON’T"
82
+ end
83
+
84
+ it 'handles missing attributes errors gracefully for lean model selects' do
85
+ UserGIGOWithSuperSubject.select(:id).find(id).subject.must_be_nil
70
86
  end
71
87
 
72
88
  end
data/test/test_helper.rb CHANGED
@@ -50,6 +50,10 @@ module GIGO
50
50
 
51
51
  private
52
52
 
53
+ def activerecord_30?
54
+ ::ActiveRecord::VERSION::STRING < '3.1'
55
+ end
56
+
53
57
  def setup_schema
54
58
  ::ActiveRecord::Base.class_eval do
55
59
  connection.instance_eval do
@@ -94,7 +98,7 @@ module GIGO
94
98
  self.table_name = :users
95
99
  gigo_column :subject
96
100
  def subject
97
- super.upcase
101
+ super.try(:upcase)
98
102
  end
99
103
  end
100
104
 
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: gigo-activerecord
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.0
5
+ version: 1.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ken Collins
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-21 00:00:00.000000000 Z
12
+ date: 2013-06-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gigo
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  - !ruby/object:Gem::Version
149
149
  segments:
150
150
  - 0
151
- hash: -2101830360572712562
151
+ hash: -1606933277418764219
152
152
  version: '0'
153
153
  none: false
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  - !ruby/object:Gem::Version
158
158
  segments:
159
159
  - 0
160
- hash: -2101830360572712562
160
+ hash: -1606933277418764219
161
161
  version: '0'
162
162
  none: false
163
163
  requirements: []