Skip to content

Commit

Permalink
Updating nested_attributes compatibility with Rails 2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva authored and josevalim committed Nov 30, 2009
1 parent e80ffb5 commit 79fd1c2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion remarkable_activerecord/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end

########### Specs

RAILS_VERSIONS = ['2.2.2', '2.3.4']
RAILS_VERSIONS = ['2.2.2', '2.3.4', '2.3.5']

desc "Run the specs under spec with supported Rails versions"
task :pre_commit do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def allows_destroy?
return true unless @options.key?(:allow_destroy)

@subject.instance_eval <<-ALLOW_DESTROY
def assign_nested_attributes_for_#{reflection_type}_association(association, attrs, allow)
return allow
def assign_nested_attributes_for_#{reflection_type}_association(association, *args)
if self.respond_to?(:nested_attributes_options)
self.nested_attributes_options[association.to_sym][:allow_destroy]
else
args.last
end
end
ALLOW_DESTROY

Expand Down Expand Up @@ -73,7 +77,11 @@ def reflection_type
end

def reject_if_proc
subject_class.reject_new_nested_attributes_procs[@association.to_sym]
if subject_class.respond_to?(:nested_attributes_options)
subject_class.nested_attributes_options[@association.to_sym][:reject_if]
else
subject_class.reject_new_nested_attributes_procs[@association.to_sym]
end
end

end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

if RAILS_VERSION == '2.3.3'
if RAILS_VERSION >= '2.3.3'
describe 'accept_nested_attributes_for' do
include ModelBuilder

Expand Down
2 changes: 1 addition & 1 deletion remarkable_activerecord/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8
require 'rubygems'

RAILS_VERSION = ENV['RAILS_VERSION'] || '2.3.4'
RAILS_VERSION = ENV['RAILS_VERSION'] || '2.3.5'

gem 'activesupport', RAILS_VERSION
require 'active_support'
Expand Down
2 changes: 1 addition & 1 deletion remarkable_rails/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ end

########### Specs

RAILS_VERSIONS = ['2.2.2', '2.3.4']
RAILS_VERSIONS = ['2.2.2', '2.3.4', '2.3.5']

desc "Run the specs under spec with supported Rails versions"
task :pre_commit do
Expand Down
3 changes: 1 addition & 2 deletions remarkable_rails/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'rubygems'

RAILS_ENV = 'test'
RAILS_VERSION = ENV['RAILS_VERSION'] || '2.3.4'
RAILS_VERSION = ENV['RAILS_VERSION'] || '2.3.5'

# Load Rails
gem 'activesupport', RAILS_VERSION
Expand Down Expand Up @@ -43,4 +43,3 @@

# Register folders to example groups
Spec::Example::ExampleGroupFactory.register(:action_controller, Spec::Rails::Example::ControllerExampleGroup)

0 comments on commit 79fd1c2

Please sign in to comment.