Permalink
Browse files

Add support for Rails 3.0

  • Loading branch information...
1 parent 14b3efc commit 1750411c1b878a8553a1160c354147c6d1067cf0 @carlosantoniodasilva committed Jan 25, 2012
Showing with 41 additions and 4 deletions.
  1. +1 −1 .gitignore
  2. +1 −0 .travis.yml
  3. +14 −0 Gemfile-rails.3.0.x
  4. +7 −1 lib/i18n_alchemy/proxy.rb
  5. +10 −2 test/i18n_alchemy/proxy_test.rb
  6. +8 −0 test/test_helper.rb
View
@@ -1,4 +1,4 @@
pkg/*
*.gem
.bundle
-Gemfile.lock
+Gemfile*.lock
View
@@ -1,5 +1,6 @@
before_install: gem update --system
gemfile:
+ - Gemfile-rails.3.0.x
- Gemfile-rails.3.1.x
- Gemfile
rvm:
View
@@ -0,0 +1,14 @@
+source "http://rubygems.org"
+
+gemspec
+
+gem "activerecord", "~> 3.0.0"
+gem "activesupport", "~> 3.0.0"
+
+platform :jruby do
+ gem "activerecord-jdbcsqlite3-adapter", "~> 1.2.0"
+end
+
+platform :ruby do
+ gem "sqlite3", "~> 1.3.4"
+end
@@ -29,8 +29,14 @@ def attributes=(attributes)
@target.attributes = parse_attributes(attributes)
end
+ # This method is added to the proxy even thought it does not exist in
+ # Rails 3.0 (only >= 3.1).
def assign_attributes(attributes, *args)
- @target.assign_attributes(parse_attributes(attributes), *args)
+ if @target.respond_to?(:assign_attributes)
+ @target.assign_attributes(parse_attributes(attributes), *args)
+ else
+ self.attributes = attributes
+ end
end
def update_attributes(attributes, *args)
@@ -175,7 +175,11 @@ def test_initializes_proxy_with_attributes
def test_initializes_proxy_with_attributes_and_skips_mass_assignment_security_protection_when_without_protection_is_used
@localized = @product.localized(attributes_hash, :without_protection => true)
- assert_equal 'My Precious!', @localized.my_precious
+ if support_assign_attributes_without_protection?
+ assert_equal 'My Precious!', @localized.my_precious
+ else
+ assert_nil @localized.my_precious
+ end
assert_equal 1, @localized.quantity
end
@@ -198,7 +202,11 @@ def test_new_with_attr_protected_attributes
def test_assign_attributes_skips_mass_assignment_security_protection_when_without_protection_is_used
@localized.assign_attributes(attributes_hash, :without_protection => true)
- assert_equal 'My Precious!', @localized.my_precious
+ if support_assign_attributes_without_protection?
+ assert_equal 'My Precious!', @localized.my_precious
+ else
+ assert_nil @localized.my_precious
+ end
assert_equal 1, @localized.quantity
end
View
@@ -16,3 +16,11 @@
require "db/test_schema"
Dir["test/models/*.rb"].each { |file| require File.expand_path(file) }
+
+class MiniTest::Unit::TestCase
+ # AR 3.0 does not have assign_attributes and without_protection option, so we
+ # are going to skip such tests in this version.
+ def support_assign_attributes_without_protection?
+ @support_assign_attributes ||= ActiveRecord::VERSION::STRING >= "3.1.0"
+ end
+end

0 comments on commit 1750411

Please sign in to comment.