default_value_for 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{default_value_for}
3
- s.version = "1.0.5"
3
+ s.version = "1.0.6"
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}
@@ -79,27 +79,26 @@ module DefaultValueFor
79
79
  end
80
80
 
81
81
  module InstanceMethods
82
- def initialize_with_defaults(attrs = nil, *args)
83
- initialize_without_defaults(attrs, *args) do
84
- if attrs
85
- stringified_attrs = attrs.stringify_keys
86
- safe_attrs = if respond_to? :sanitize_for_mass_assignment
87
- sanitize_for_mass_assignment(stringified_attrs)
88
- else
89
- remove_attributes_protected_from_mass_assignment(stringified_attrs)
90
- end
91
- safe_attribute_names = safe_attrs.keys.map do |x|
92
- x.to_s
93
- end
82
+ def initialize_with_defaults(attrs = nil, *args, &block)
83
+ initialize_without_defaults(attrs, *args, &block)
84
+ if attrs
85
+ stringified_attrs = attrs.stringify_keys
86
+ safe_attrs = if respond_to? :sanitize_for_mass_assignment
87
+ sanitize_for_mass_assignment(stringified_attrs)
88
+ else
89
+ remove_attributes_protected_from_mass_assignment(stringified_attrs)
90
+ end
91
+ safe_attribute_names = safe_attrs.keys.map do |x|
92
+ x.to_s
94
93
  end
95
- self.class._default_attribute_values.each do |attribute, container|
96
- if safe_attribute_names.nil? || !safe_attribute_names.any? { |attr_name| attr_name =~ /^#{attribute}($|\()/ }
97
- __send__("#{attribute}=", container.evaluate(self))
98
- changed_attributes.delete(attribute)
99
- end
94
+ end
95
+ self.class._default_attribute_values.each do |attribute, container|
96
+ if safe_attribute_names.nil? || !safe_attribute_names.any? { |attr_name| attr_name =~ /^#{attribute}($|\()/ }
97
+ __send__("#{attribute}=", container.evaluate(self))
98
+ changed_attributes.delete(attribute)
100
99
  end
101
- yield(self) if block_given?
102
100
  end
101
+ yield(self) if block_given?
103
102
  end
104
103
  end
105
104
  end
data/test.rb CHANGED
@@ -18,7 +18,7 @@
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'
21
+ want_rails_version = '~> 3.1.0'
22
22
 
23
23
  require 'rubygems'
24
24
  gem 'rails', want_rails_version
@@ -220,19 +220,18 @@ class DefaultValuePluginTest < Test::Unit::TestCase
220
220
  assert_same object, $instance
221
221
  end
222
222
 
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
+ def test_can_specify_default_value_via_association
224
+ user = User.create(:username => 'Kanako', :default_number => 123)
225
+ define_model_class do
226
+ belongs_to :user
227
+
228
+ default_value_for :number do |n|
229
+ n.user.default_number
230
+ end
231
+ end
232
+ object = user.numbers.create
233
+ assert_equal 123, object.number
234
+ end
236
235
 
237
236
  def test_default_values
238
237
  define_model_class do
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: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ - 6
10
+ version: 1.0.6
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-08-11 00:00:00 +02:00
18
+ date: 2011-09-08 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21