Permalink
Browse files

Working on adding support for Rails 3 and functioning as a gem

  • Loading branch information...
samlown committed Jan 21, 2011
1 parent 817e292 commit a67d685a2ae397ef53fafa59ecb2d15fcdf34746
View
@@ -0,0 +1,4 @@
+
+source :rubygems
+gemspec
+
View
@@ -0,0 +1,36 @@
+PATH
+ remote: .
+ specs:
+ translate_columns (1.1.0)
+ activerecord (~> 3.0.0)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activesupport (3.0.3)
+ arel (2.0.7)
+ builder (2.1.2)
+ i18n (0.5.0)
+ mocha (0.9.10)
+ rake
+ rake (0.8.7)
+ sqlite3 (1.3.3)
+ tzinfo (0.3.24)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activerecord (~> 3.0.0)
+ mocha (~> 0.9.3)
+ sqlite3 (~> 1.3.3)
+ translate_columns!
View
@@ -8,6 +8,7 @@ task :default => :test
desc 'Test the translate_columns plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
+ t.libs << 'test/lib'
t.pattern = 'test/*_test.rb'
t.verbose = true
end
View
@@ -0,0 +1 @@
+1.1.0
View
@@ -1,7 +1,3 @@
-# Include hook code here
require 'translate_columns'
-ActiveRecord::Base.class_eval do
- include TranslateColumns
-end
View
@@ -1,7 +1,8 @@
-#
+# encoding: utf-8
+#
# TranslateColumns
#
-# Copyright (c) 2007 Samuel Lown <me@samlown.com>
+# Copyright (c)2007-2011 Samuel Lown <me@samlown.com>
#
module TranslateColumns
@@ -183,7 +184,7 @@ def translation
# before saving. This means the base records validation checks will always
# be used.
#
- def save_with_translation(perform_validation = true)
+ def save_with_translation(*args)
if perform_validation && valid? || !perform_validation
translation.save(false) if (translation)
disable_translation
@@ -216,12 +217,11 @@ def attributes_with_locale=(new_attributes, guard_protected_attributes = true)
attributes = new_attributes.dup
attributes.stringify_keys!
- attributes = remove_attributes_protected_from_mass_assignment(attributes) if guard_protected_attributes
+ attributes = sanitize_for_mass_assignment(attributes) if guard_protected_attributes
send(:locale=, attributes["locale"]) if attributes.has_key?("locale") and respond_to?(:locale=)
send(:attributes_without_locale=, attributes, guard_protected_attributes)
end
end
-
end
@@ -1,5 +1,6 @@
class Document < ActiveRecord::Base
-
+ include TranslateColumns
+
has_many :translations, :class_name => 'DocumentTranslation'
translate_columns :title, :body
@@ -1,4 +1,3 @@
-require 'rubygems'
require 'active_record'
require 'active_record/fixtures'
@@ -1,10 +1,10 @@
-require 'test/lib/activerecord_connector'
-require 'test/fixtures/schema.rb'
+require 'activerecord_connector'
+require File.join(File.dirname(__FILE__), '../fixtures/schema.rb')
module ActiverecordTestHelper
FIXTURES_PATH = File.join(File.dirname(__FILE__), '/../fixtures')
dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
- dep.load_paths.unshift FIXTURES_PATH
+ dep.autoload_paths.unshift FIXTURES_PATH
end
@@ -1,7 +1,11 @@
-require 'test/lib/activerecord_test_helper'
+# encoding: utf-8
+
+require 'bundler/setup'
require 'test/unit'
require 'mocha'
-require 'init'
+
+require 'activerecord_test_helper'
+require 'translate_columns'
class TranslateColumnsTest < Test::Unit::TestCase
@@ -111,15 +115,15 @@ def test_failed_validations
doc = Document.find(:first)
doc.title = "a"
assert !doc.save
- assert doc.errors.on(:title)
+ assert !doc.errors[:title].empty?
end
def test_failed_validations_on_translation
I18n.locale = 'es'
doc = Document.find(:first)
doc.title = "a"
assert !doc.save
- assert doc.errors.on(:title)
+ assert !doc.errors[:title].empty?
end
def test_locale_attribute_detection
View
@@ -0,0 +1,28 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{translate_columns}
+ s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION')).strip
+
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.5") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Sam Lown"]
+ s.date = %q{2011-01-21}
+ s.description = %q{Automatically translate ActiveRecord columns using a second model containing the translations.}
+ s.email = %q{me@samlown.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README"
+ ]
+ s.homepage = %q{http://github.com/samlown/translate_columns}
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Use fields from other translation models easily}
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.require_paths = ["lib"]
+
+ s.add_dependency("activerecord", "~> 3.0.0")
+ s.add_development_dependency(%q<mocha>, "~> 0.9.3")
+ s.add_development_dependency(%q<sqlite3>, "~> 1.3.3")
+end
+

0 comments on commit a67d685

Please sign in to comment.