default_value_for 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{default_value_for}
3
- s.version = "1.0.4"
3
+ s.version = "1.0.5"
4
4
  s.summary = %q{Provides a way to specify default values for ActiveRecord models}
5
5
  s.description = %q{The default_value_for plugin allows one to define default values for ActiveRecord models in a declarative manner}
6
6
  s.email = %q{info@phusion.nl}
@@ -1,30 +1,39 @@
1
- # Copyright (c) 2008, 2009, 2010, 2011 Phusion
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- # Rails 3 initialization
22
- module DefaultValueFor
23
- class Railtie < Rails::Railtie
24
- initializer 'default_value_for.insert_into_active_record' do
25
- ActiveSupport.on_load :active_record do
26
- ActiveRecord::Base.extend(DefaultValueFor::ClassMethods)
27
- end
28
- end
29
- end
30
- end
1
+ # Copyright (c) 2008, 2009, 2010, 2011 Phusion
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ # Rails 3 initialization
22
+
23
+ module DefaultValueFor
24
+ def self.initialize_railtie
25
+ ActiveSupport.on_load :active_record do
26
+ DefaultValueFor.initialize_active_record_extensions
27
+ end
28
+ end
29
+
30
+ def self.initialize_active_record_extensions
31
+ ActiveRecord::Base.extend(DefaultValueFor::ClassMethods)
32
+ end
33
+
34
+ class Railtie < Rails::Railtie
35
+ initializer 'default_value_for.insert_into_active_record' do
36
+ DefaultValueFor.initialize_railtie
37
+ end
38
+ end
39
+ end
data/test.rb CHANGED
@@ -18,14 +18,21 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ want_rails_version = '~> 3.1.0.rc1'
22
+
21
23
  require 'rubygems'
22
- gem 'activerecord', '~> 3.1.0.rc1'
24
+ gem 'rails', want_rails_version
25
+ gem 'activerecord', want_rails_version
26
+ begin
27
+ require 'rails/railtie'
28
+ rescue LoadError
29
+ end
23
30
  require 'active_record'
24
31
  require 'test/unit'
32
+ require 'active_support/dependencies'
25
33
  require 'active_support/core_ext/logger'
26
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
27
- require File.dirname(__FILE__) + '/lib/default_value_for'
28
- require File.dirname(__FILE__) + '/init'
34
+ $LOAD_PATH.unshift File.expand_path("lib", File.dirname(__FILE__))
35
+ require 'default_value_for'
29
36
  Dir.chdir(File.dirname(__FILE__))
30
37
 
31
38
  if RUBY_PLATFORM == "java"
@@ -53,6 +60,11 @@ ActiveRecord::Base.connection.create_table(:numbers, :force => true) do |t|
53
60
  t.timestamp :timestamp
54
61
  end
55
62
 
63
+ if defined?(Rails::Railtie)
64
+ DefaultValueFor.initialize_railtie
65
+ DefaultValueFor.initialize_active_record_extensions
66
+ end
67
+
56
68
  class User < ActiveRecord::Base
57
69
  has_many :numbers, :class_name => 'TestClass'
58
70
  end
@@ -208,24 +220,25 @@ class DefaultValuePluginTest < Test::Unit::TestCase
208
220
  assert_same object, $instance
209
221
  end
210
222
 
211
- def test_can_specify_default_value_via_association
212
- user = User.create(:username => 'Kanako', :default_number => 123)
213
- define_model_class do
214
- belongs_to :user
215
-
216
- default_value_for :number do |n|
217
- n.user.default_number
218
- end
219
- end
220
- object = user.numbers.create
221
- assert_equal 123, object.number
222
- end
223
+ # This is no longer supported starting from Rails 3.1 thanks to ActiveRecord changes.
224
+ # def test_can_specify_default_value_via_association
225
+ # user = User.create(:username => 'Kanako', :default_number => 123)
226
+ # define_model_class do
227
+ # belongs_to :user
228
+ #
229
+ # default_value_for :number do |n|
230
+ # n.user.default_number
231
+ # end
232
+ # end
233
+ # object = user.numbers.create
234
+ # assert_equal 123, object.number
235
+ # end
223
236
 
224
237
  def test_default_values
225
238
  define_model_class do
226
239
  default_values :type => "normal",
227
- :number => lambda { 10 + 5 },
228
- :timestamp => lambda {|_| Time.now }
240
+ :number => lambda { 10 + 5 },
241
+ :timestamp => lambda {|_| Time.now }
229
242
  end
230
243
 
231
244
  object = TestClass.new
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: default_value_for
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Hongli Lai
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-22 00:00:00 +02:00
18
+ date: 2011-08-11 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21