Skip to content

Commit

Permalink
Add support for Rails 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Jan 25, 2012
1 parent 14b3efc commit 1750411
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
pkg/*
*.gem
.bundle
Gemfile.lock
Gemfile*.lock
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,5 +1,6 @@
before_install: gem update --system
gemfile:
- Gemfile-rails.3.0.x
- Gemfile-rails.3.1.x
- Gemfile
rvm:
Expand Down
14 changes: 14 additions & 0 deletions Gemfile-rails.3.0.x
@@ -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
8 changes: 7 additions & 1 deletion lib/i18n_alchemy/proxy.rb
Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions test/i18n_alchemy/proxy_test.rb
Expand Up @@ -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

Expand All @@ -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

Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.rb
Expand Up @@ -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.