attr_default 0.5.7 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # gem 'hobosupport', '0.9.103', :path => '../web/vendor/gems/hobosupport-0.9.103'
4
- # gem 'hobofields', '0.9.103', :path => '../web/vendor/gems/hobofields-0.9.103'
5
-
6
- # Specify your gem's dependencies in attr_default.gemspec
7
3
  gemspec
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'appraisal'
4
+ require 'rubygems'
5
+ require 'bundler/setup'
3
6
 
4
7
  task :default => :test
5
8
 
6
9
  desc "Run unit tests."
7
10
  task :test do
8
- ruby "test/test_attr_default.rb"
11
+ ruby "test/attr_default_test.rb"
9
12
  end
@@ -1,9 +1,9 @@
1
1
  require File.expand_path('../lib/attr_default/version', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
- gem.add_development_dependency 'rack', '~> 1.1.0'
4
+ gem.add_development_dependency 'appraisal'
5
5
  gem.add_development_dependency 'rake', '~>0.9'
6
- gem.add_development_dependency 'rails', '2.3.14'
6
+ gem.add_development_dependency 'pry'
7
7
  gem.add_development_dependency 'sqlite3'
8
8
  gem.add_development_dependency 'hobofields', '0.9.103'
9
9
  gem.authors = ["Colin Kelley", "Nick Burwell"]
@@ -9,7 +9,7 @@ module AttrDefault
9
9
  _attr_defaults[attr_name] = default
10
10
 
11
11
  define_method(attr_name) do
12
- if new_record? && !@_attr_defaults_set_from_clone && !_attr_default_set[attr_name]
12
+ if new_record? && !@_attr_defaults_set_from_dup && !_attr_default_set[attr_name]
13
13
  reset_to_default_value(attr_name)
14
14
  end
15
15
  read_attribute_with_fixups(attr_name)
@@ -89,16 +89,30 @@ module AttrDefault
89
89
  self.class.send(:create_time_zone_conversion_attribute?, attr_name, self.class.columns_hash[attr_name])
90
90
  end
91
91
 
92
- def clone
93
- result = super
94
- result.created_at = nil unless !result.class.columns_hash.has_key?('created_at')
95
- result.updated_at = nil unless !result.class.columns_hash.has_key?('updated_at')
96
- if self.new_record?
97
- result.instance_variable_set(:@_attr_default_set, self._attr_default_set.dup)
98
- else
99
- result.instance_variable_set(:@_attr_defaults_set_from_clone, true)
92
+ if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('3.1')
93
+ def dup
94
+ result = super
95
+ result.created_at = nil unless !result.class.columns_hash.has_key?('created_at')
96
+ result.updated_at = nil unless !result.class.columns_hash.has_key?('updated_at')
97
+ if self.new_record?
98
+ result.instance_variable_set(:@_attr_default_set, self._attr_default_set.dup)
99
+ else
100
+ result.instance_variable_set(:@_attr_defaults_set_from_dup, true)
101
+ end
102
+ result
103
+ end
104
+ else
105
+ def clone
106
+ result = super
107
+ result.created_at = nil unless !result.class.columns_hash.has_key?('created_at')
108
+ result.updated_at = nil unless !result.class.columns_hash.has_key?('updated_at')
109
+ if self.new_record?
110
+ result.instance_variable_set(:@_attr_default_set, self._attr_default_set.dup)
111
+ else
112
+ result.instance_variable_set(:@_attr_defaults_set_from_dup, true)
113
+ end
114
+ result
100
115
  end
101
- result
102
116
  end
103
117
  end
104
118
  end
@@ -1,3 +1,3 @@
1
1
  module AttrDefault
2
- VERSION = "0.5.7"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -17,6 +17,20 @@ else
17
17
  database_adapter = "sqlite3"
18
18
  end
19
19
 
20
+ SAVE_NO_VALIDATE =
21
+ if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('3.0')
22
+ {:validate => false}
23
+ else
24
+ false
25
+ end
26
+
27
+ DUP_METHOD =
28
+ if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('3.1')
29
+ :dup
30
+ else
31
+ :clone
32
+ end
33
+
20
34
  File.unlink('test.sqlite3') rescue nil
21
35
  ActiveRecord::Base.logger = Logger.new(STDERR)
22
36
  ActiveRecord::Base.logger.level = Logger::WARN
@@ -29,6 +43,7 @@ ActiveRecord::Base.connection.create_table(:test_users, :force => true) do |t|
29
43
  t.string :first_name, :default => ''
30
44
  t.string :last_name
31
45
  t.string :domain, :default => 'example.com'
46
+ t.string :password
32
47
  t.timestamp :timestamp
33
48
  end
34
49
 
@@ -120,11 +135,11 @@ class AttrDefaultTest < Test::Unit::TestCase
120
135
 
121
136
  def test_return_the_ActiveRecord_native_type_not_the_lambda_type
122
137
  u = TestUser.new
123
- assert_equal 'ActiveSupport::TimeWithZone', u.timestamp.class.name
138
+ assert_equal ActiveSupport::TimeWithZone, u.timestamp.class
124
139
  begin
125
140
  old_time_zone, Time.zone = Time.zone, 'Central Time (US & Canada)'
126
141
  u = TestUser.new
127
- assert_equal 'ActiveSupport::TimeWithZone', u.timestamp.class.name
142
+ assert_equal ActiveSupport::TimeWithZone, u.timestamp.class
128
143
  assert_match /Central Time/, u.timestamp.time_zone.to_s
129
144
  ensure
130
145
  Time.zone = old_time_zone
@@ -203,24 +218,24 @@ class AttrDefaultTest < Test::Unit::TestCase
203
218
  assert_equal "initial.com", domain.domain
204
219
  end
205
220
 
206
- def test_clone_touched_state_when_cloned_before_save_new_record_true
221
+ def test_dup_touched_state_when_duped_before_save_new_record_true
207
222
  u = TestUser.new :first_name => 'John', :last_name => 'Doe'
208
223
  u.last_name = 'overridden'
209
- u2 = u.clone
224
+ u2 = u.send(DUP_METHOD)
210
225
  assert_equal 'overridden', u2.read_attribute(:last_name)
211
226
  assert_equal 'overridden', u2.last_name
212
227
  end
213
228
 
214
- def test_clone_touched_state_when_cloned_after_save_new_record_false
215
- u = TestUser.new :first_name => 'John', :last_name => 'Doe'
229
+ def test_dup_touched_state_when_duped_after_save_new_record_false
230
+ u = TestUser.new(:first_name => 'John', :last_name => 'Doe')
216
231
  u.last_name = 'overridden'
217
- u2 = u.clone
232
+ u2 = u.send(DUP_METHOD)
218
233
  u2.save!
219
234
  u.save!
220
- assert u.clone.instance_variable_get(:@_attr_defaults_set_from_clone)
221
- assert_equal 'overridden', u.clone.last_name
235
+ assert u.send(DUP_METHOD).instance_variable_get(:@_attr_defaults_set_from_dup)
236
+ assert_equal 'overridden', u.send(DUP_METHOD).last_name
222
237
  ufind = TestUser.find(u.id)
223
- u3 = ufind.clone
238
+ u3 = ufind.send(DUP_METHOD)
224
239
  assert_equal 'overridden', u3.read_attribute(:last_name), u3.attributes.inspect
225
240
  assert_equal 'overridden', u3.last_name
226
241
  u3.save!
@@ -237,7 +252,7 @@ class AttrDefaultTest < Test::Unit::TestCase
237
252
  # not touched or saved yet, still SQL default
238
253
  assert_equal "domain.com", domain.read_attribute(:domain)
239
254
 
240
- domain.save(false)
255
+ domain.save(SAVE_NO_VALIDATE)
241
256
 
242
257
  # now it should be set to Ruby default
243
258
  assert_equal "initial.com", domain.read_attribute(:domain)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_default
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,24 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-09-28 00:00:00.000000000 Z
13
+ date: 2013-09-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: rack
16
+ name: appraisal
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ~>
20
+ - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
- version: 1.1.0
22
+ version: '0'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ~>
28
+ - - ! '>='
29
29
  - !ruby/object:Gem::Version
30
- version: 1.1.0
30
+ version: '0'
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: rake
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -45,21 +45,21 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0.9'
47
47
  - !ruby/object:Gem::Dependency
48
- name: rails
48
+ name: pry
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - '='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.3.14
54
+ version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
- - - '='
60
+ - - ! '>='
61
61
  - !ruby/object:Gem::Version
62
- version: 2.3.14
62
+ version: '0'
63
63
  - !ruby/object:Gem::Dependency
64
64
  name: sqlite3
65
65
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +108,7 @@ files:
108
108
  - lib/attr_default.rb
109
109
  - lib/attr_default/railtie.rb
110
110
  - lib/attr_default/version.rb
111
- - test/test_attr_default.rb
111
+ - test/attr_default_test.rb
112
112
  homepage: https://github.com/RingRevenue/attr_default
113
113
  licenses: []
114
114
  post_install_message:
@@ -123,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  segments:
125
125
  - 0
126
- hash: -3904188318678435227
126
+ hash: -1415476952422739747
127
127
  required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  segments:
134
134
  - 0
135
- hash: -3904188318678435227
135
+ hash: -1415476952422739747
136
136
  requirements: []
137
137
  rubyforge_project:
138
138
  rubygems_version: 1.8.25
@@ -143,4 +143,4 @@ summary: ! 'Dynamic Ruby defaults for ActiveRecord attributes. These are lazy ev
143
143
  dynamic defaults to depend on attributes that are assigned after initialization,
144
144
  or on other dynamic defaults.'
145
145
  test_files:
146
- - test/test_attr_default.rb
146
+ - test/attr_default_test.rb