translatable 0.3.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,104 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class Paper
5
+ end
6
+
7
+ class TranslatedPaper
8
+ end
9
+
10
+ class DefiningBaseTest < Test::Unit::TestCase
11
+ setup do
12
+ @base = Translatable::Base.new(Paper)
13
+ end
14
+
15
+ #context "Defining" do
16
+ test "should Simple field" do
17
+ @base.field :title
18
+
19
+ assert_equal [[:title, {}]], @base.fields
20
+ end
21
+
22
+ test "should Several fields" do
23
+ @base.field :title
24
+ @base.field :content, :presence => true
25
+
26
+ assert_equal [[:title, {}], [:content, {:presence => true}]], @base.fields
27
+ end
28
+
29
+ test "should Have mapping" do
30
+ @base.field :title
31
+ @base.field :content, :as => :paper_content, :presence => true
32
+
33
+ assert_equal({:title => :title, :content => :paper_content, :locale => :locale}, @base.mapping)
34
+ end
35
+
36
+ test "should Have mapping (with locale)" do
37
+ @base.field :title
38
+ @base.field :content, :as => :paper_content, :presence => true
39
+ @base.locale_key :locale, :as => :language
40
+
41
+ assert_equal({:title => :title, :content => :paper_content, :locale => :language}, @base.mapping)
42
+ end
43
+
44
+ test "should Translation model (as class)" do
45
+ @base.class_name TranslatedPaper
46
+
47
+ assert_equal TranslatedPaper, @base.translation_model
48
+ end
49
+
50
+ test "should Translation model (as string)" do
51
+ @base.class_name "TranslatedPaper"
52
+
53
+ assert_equal TranslatedPaper, @base.translation_model
54
+ end
55
+
56
+ test "should Translation model (as symbol)" do
57
+ @base.class_name :TranslatedPaper
58
+
59
+ assert_equal TranslatedPaper, @base.translation_model
60
+ end
61
+
62
+ test "should Origin key" do
63
+ @base.foreign_key :article_id
64
+
65
+ assert_equal :article_id, @base.origin_key
66
+ end
67
+
68
+ test "should Reflection name" do
69
+ @base.reflection_name :article
70
+
71
+ assert_equal :article, @base.origin_reflection_name
72
+ end
73
+
74
+ test "should Locale key" do
75
+ @base.locale_key :language
76
+
77
+ assert_equal :language, @base.locale_column
78
+ end
79
+ #end
80
+ end
81
+
82
+ class DefaultingBaseTest < Test::Unit::TestCase
83
+ setup do
84
+ @base = Translatable::Base.new(Paper)
85
+ end
86
+
87
+ #context "Defaulting" do
88
+ test "should Translation model" do
89
+ assert_equal TranslatedPaper, @base.translation_model
90
+ end
91
+
92
+ test "should Origin key" do
93
+ assert_equal :origin_id, @base.origin_key
94
+ end
95
+
96
+ test "should Reflection name" do
97
+ assert_equal :origin, @base.origin_reflection_name
98
+ end
99
+
100
+ test "should Locale key" do
101
+ assert_equal :locale, @base.locale_column
102
+ end
103
+ #end
104
+ end
@@ -14,12 +14,16 @@ class ModelGeneratorTest < Rails::Generators::TestCase
14
14
  assert_file "app/models/article.rb", <<CONTENT
15
15
  class Article < ActiveRecord::Base
16
16
  translatable do
17
- translatable :title, :presence => true#, :uniqueness => true
18
- translatable :content, :presence => true#, :uniqueness => true
19
- #translatable_model 'TranslatedArticle'
20
- #translatable_origin :article
21
- #translatable_locale :locale
17
+ field :title, :presence => true#, :uniqueness => true
18
+ field :content, :presence => true#, :uniqueness => true
19
+ #class_name 'TranslatedArticle'
20
+ #reflection_name :article
21
+ #foreign_key :origin_id
22
+ #locale_key :locale
22
23
  end
24
+
25
+ #accepts_nested_attributes_for :translations, :current_translation
26
+ #attr_accessible :translations_attributes, :current_translation_attributes
23
27
  end
24
28
  CONTENT
25
29
  assert_migration "db/migrate/create_articles.rb", <<CONTENT
@@ -39,12 +43,16 @@ CONTENT
39
43
  assert_file "app/models/article.rb", <<CONTENT
40
44
  class Article < ActiveRecord::Base
41
45
  translatable do
42
- translatable :title, :presence => true#, :uniqueness => true
43
- translatable :content, :presence => true#, :uniqueness => true
44
- translatable_model 'ArticleTranslation'
45
- translatable_origin :post
46
- translatable_locale :language
46
+ field :title, :presence => true#, :uniqueness => true
47
+ field :content, :presence => true#, :uniqueness => true
48
+ class_name 'ArticleTranslation'
49
+ reflection_name :post
50
+ #foreign_key :origin_id
51
+ locale_key :language
47
52
  end
53
+
54
+ #accepts_nested_attributes_for :translations, :current_translation
55
+ #attr_accessible :translations_attributes, :current_translation_attributes
48
56
  end
49
57
  CONTENT
50
58
  assert_migration "db/migrate/create_articles.rb", <<CONTENT
@@ -66,12 +74,16 @@ CONTENT
66
74
  assert_file "app/models/article.rb", <<CONTENT
67
75
  class Article < ActiveRecord::Base
68
76
  translatable do
69
- translatable :title, :presence => true#, :uniqueness => true
70
- translatable :content, :presence => true#, :uniqueness => true
71
- #translatable_model 'TranslatedArticle'
72
- #translatable_origin :article
73
- #translatable_locale :locale
77
+ field :title, :presence => true#, :uniqueness => true
78
+ field :content, :presence => true#, :uniqueness => true
79
+ #class_name 'TranslatedArticle'
80
+ #reflection_name :article
81
+ #foreign_key :origin_id
82
+ #locale_key :locale
74
83
  end
84
+
85
+ #accepts_nested_attributes_for :translations, :current_translation
86
+ #attr_accessible :translations_attributes, :current_translation_attributes
75
87
  attr_accessor :created_at, :updated_at
76
88
  end
77
89
  CONTENT
@@ -11,18 +11,18 @@ class TranslationGeneratorTest < Rails::Generators::TestCase
11
11
 
12
12
  should "Create required files (default)" do
13
13
  run_generator %w(article title:string content:string)
14
- assert_file "app/models/translatable_article.rb", <<CONTENT
15
- class TranslatableArticle < ActiveRecord::Base
14
+ assert_file "app/models/translated_article.rb", <<CONTENT
15
+ class TranslatedArticle < ActiveRecord::Base
16
16
  # This class deals purely with translations themselves. Hence, any edition of
17
17
  # should be avoided.
18
18
  # In later gem version its existance might not be necessary.
19
19
  #attr_protected :origin_id, :locale
20
20
  end
21
21
  CONTENT
22
- assert_migration "db/migrate/create_translatable_articles.rb", <<CONTENT
23
- class CreateTranslatableArticles < ActiveRecord::Migration
22
+ assert_migration "db/migrate/create_translated_articles.rb", <<CONTENT
23
+ class CreateTranslatedArticles < ActiveRecord::Migration
24
24
  def change
25
- create_table :translatable_articles do |t|
25
+ create_table :translated_articles do |t|
26
26
  t.string :title
27
27
  t.string :content
28
28
  t.integer :origin_id
@@ -1,4 +1,5 @@
1
1
  require 'logger'
2
+ require 'active_record'
2
3
 
3
4
  ActiveRecord::Base.establish_connection(
4
5
  :adapter => "sqlite3",
@@ -1,6 +1,3 @@
1
- require 'active_record'
2
- require 'translatable'
3
-
4
1
  class CreateMessagesTables < ActiveRecord::Migration
5
2
  def up
6
3
  create_table(:writers, :force => true) do |t|
@@ -9,11 +6,11 @@ class CreateMessagesTables < ActiveRecord::Migration
9
6
  t.timestamps
10
7
  end
11
8
 
12
- create_table(:translated_messages) do |t|
13
- t.string :title, :null => false
14
- t.string :content, :null => false
15
- t.integer :message_id, :null => false
16
- t.string :locale, :null => false, :limit => 2
9
+ create_table(:message_translations) do |t|
10
+ t.string :title, :null => false
11
+ t.string :content, :null => false
12
+ t.integer :origin_id, :null => false
13
+ t.string :locale, :null => false, :limit => 2
17
14
  t.integer :writer_id
18
15
 
19
16
  t.timestamps
@@ -28,7 +25,7 @@ class CreateMessagesTables < ActiveRecord::Migration
28
25
 
29
26
  def down
30
27
  drop_table(:writers)
31
- drop_table(:translated_messages)
28
+ drop_table(:message_translations)
32
29
  drop_table(:messages)
33
30
  end
34
31
  end
@@ -39,7 +36,7 @@ class Author < ActiveRecord::Base
39
36
  validates :name, :presence => true
40
37
  end
41
38
 
42
- class TranslatedMessage < ActiveRecord::Base
39
+ class MessageTranslation < ActiveRecord::Base
43
40
  attr_accessible :title, :content
44
41
  attr_accessible :title, :content, :locale, :as => :editor
45
42
 
@@ -62,11 +59,13 @@ class Message < ActiveRecord::Base
62
59
  belongs_to :writer
63
60
 
64
61
  translatable do
65
- translatable :title, :presence => true, :uniqueness => true
66
- translatable :content, :presence => true
67
- translatable_model 'TranslatedMessage'
68
- translatable_origin :message
62
+ field :title, :presence => true, :uniqueness => true
63
+ field :content, :presence => true
64
+ class_name 'MessageTranslation'
65
+ reflection_name :message
69
66
  end
70
67
 
68
+ accepts_nested_attributes_for :translations, :current_translation
69
+ attr_accessible :translations_attributes, :current_translation_attributes
71
70
  attr_accessible :writer_id, :writer
72
71
  end
@@ -1,6 +1,3 @@
1
- require 'active_record'
2
- require 'translatable'
3
-
4
1
  class CreateNewsTables < ActiveRecord::Migration
5
2
  def up
6
3
  create_table(:authors) do |t|
@@ -9,7 +6,7 @@ class CreateNewsTables < ActiveRecord::Migration
9
6
  t.timestamps
10
7
  end
11
8
 
12
- create_table(:translatable_news) do |t|
9
+ create_table(:translated_news) do |t|
13
10
  t.string :title, :null => false
14
11
  t.string :content, :null => false
15
12
  t.integer :origin_id, :null => false
@@ -38,11 +35,11 @@ class Author < ActiveRecord::Base
38
35
  validates :name, :presence => true
39
36
  end
40
37
 
41
- class TranslatableNews < ActiveRecord::Base
38
+ class TranslatedNews < ActiveRecord::Base
42
39
  validates :title, :content, :presence => true
43
40
  validates :title, :uniqueness => true
44
41
 
45
- attr_accessible :title, :content
42
+ attr_accessible :title, :content, :locale, :origin_id
46
43
  end
47
44
 
48
45
  class News < ActiveRecord::Base
@@ -50,10 +47,11 @@ class News < ActiveRecord::Base
50
47
  belongs_to :author
51
48
 
52
49
  translatable do
53
- translatable :title
54
- translatable :content
55
- translatable_attr_accessible
50
+ field :title
51
+ field :content
56
52
  end
57
53
 
54
+ accepts_nested_attributes_for :translations, :current_translation
55
+ attr_accessible :translations_attributes, :current_translation_attributes
58
56
  attr_accessible :author_id, :author
59
57
  end
@@ -1,6 +1,3 @@
1
- require 'active_record'
2
- require 'translatable'
3
-
4
1
  class CreatePostsTables < ActiveRecord::Migration
5
2
  def up
6
3
  create_table(:writers, :force => true) do |t|
@@ -13,7 +10,7 @@ class CreatePostsTables < ActiveRecord::Migration
13
10
  t.string :title, :null => false
14
11
  t.string :content, :null => false
15
12
  t.integer :post_id, :null => false
16
- t.string :locale, :null => false, :limit => 2
13
+ t.string :language, :null => false, :limit => 2
17
14
  t.integer :writer_id
18
15
 
19
16
  t.timestamps
@@ -40,7 +37,7 @@ class Author < ActiveRecord::Base
40
37
  end
41
38
 
42
39
  class TranslatedPost < ActiveRecord::Base
43
- attr_accessible :title, :content
40
+ attr_accessible :title, :content, :language
44
41
 
45
42
  before_create :duplicate_writer_id
46
43
 
@@ -56,12 +53,15 @@ class Post < ActiveRecord::Base
56
53
  belongs_to :writer
57
54
 
58
55
  translatable do
59
- translatable :title, :as => :translated_title, :presence => true, :uniqueness => true
60
- translatable :content, :presence => true
61
- translatable_model 'TranslatedPost'
62
- translatable_origin :post
63
- translatable_attr_accessible
56
+ field :title, :as => :translated_title, :presence => true, :uniqueness => true
57
+ field :content, :presence => true
58
+ class_name 'TranslatedPost'
59
+ reflection_name :post
60
+ foreign_key :post_id
61
+ locale_key :language
64
62
  end
65
63
 
64
+ accepts_nested_attributes_for :translations, :current_translation
65
+ attr_accessible :translations_attributes, :current_translation_attributes
66
66
  attr_accessible :writer_id, :writer
67
67
  end
@@ -3,15 +3,7 @@ require 'test/unit'
3
3
  require "shoulda-context"
4
4
  require "i18n"
5
5
 
6
- begin
7
- require 'simplecov'
8
- SimpleCov.start do
9
- add_filter "/test/"
10
- add_filter "/vendor/"
11
- end
12
- rescue LoadError
13
- $stderr.puts "Simplecov is skipped"
14
- end
6
+ require "protected_attributes"
15
7
 
16
8
  begin
17
9
  Bundler.setup(:default, :development)
@@ -26,14 +18,6 @@ require 'translatable'
26
18
  require File.expand_path("support/active_record", File.dirname(__FILE__))
27
19
  require File.expand_path("support/database_cleaner", File.dirname(__FILE__))
28
20
 
29
- # Test output styling
30
- # Turn do not want to play nicelly =(, skip it then....
31
- require 'turn/autorun'
32
- Turn.config do |c|
33
- c.format = :pretty
34
- c.natural = true
35
- end
36
-
37
21
  class Test::Unit::TestCase
38
22
  include OrmSetup
39
23
 
@@ -2,14 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: translatable 1.2.2 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "translatable"
8
- s.version = "0.3.1"
9
+ s.version = "1.2.2"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["E-Max"]
12
- s.date = "2013-03-16"
14
+ s.date = "2014-01-31"
13
15
  s.description = "This game was build to make whole proccess of working with translation for DM to be almost invisble. That was THE AIM."
14
16
  s.email = "max@studentify.nl"
15
17
  s.extra_rdoc_files = [
@@ -17,7 +19,8 @@ Gem::Specification.new do |s|
17
19
  "README.rdoc"
18
20
  ]
19
21
  s.files = [
20
- ".document",
22
+ ".ruby-gemset",
23
+ ".ruby-version",
21
24
  ".travis.yml",
22
25
  "Gemfile",
23
26
  "Gemfile.lock",
@@ -28,10 +31,12 @@ Gem::Specification.new do |s|
28
31
  "lib/generators/translatable/model_generator.rb",
29
32
  "lib/generators/translatable/translation_generator.rb",
30
33
  "lib/translatable.rb",
31
- "lib/translatable/active_record.rb",
34
+ "lib/translatable/base.rb",
32
35
  "lib/translatable/engine.rb",
33
36
  "lib/translatable/generator_helper.rb",
34
- "test/cases/translatable_test.rb",
37
+ "lib/translatable/orm/active_record.rb",
38
+ "test/cases/active_record_test.rb",
39
+ "test/cases/base_test.rb",
35
40
  "test/generators/model_generator_test.rb",
36
41
  "test/generators/translation_generator_test.rb",
37
42
  "test/support/active_record.rb",
@@ -44,26 +49,25 @@ Gem::Specification.new do |s|
44
49
  ]
45
50
  s.homepage = "http://github.com/kot-begemot/translatable"
46
51
  s.licenses = ["MIT"]
47
- s.require_paths = ["lib"]
48
- s.rubygems_version = "1.8.10"
52
+ s.rubygems_version = "2.2.1"
49
53
  s.summary = "An esay way to manage the translations for datamapper"
50
54
 
51
55
  if s.respond_to? :specification_version then
52
- s.specification_version = 3
56
+ s.specification_version = 4
53
57
 
54
58
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<activerecord>, [">= 0"])
59
+ s.add_runtime_dependency(%q<activerecord>, [">= 4.0.0"])
56
60
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
57
61
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
58
62
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.0"])
59
63
  else
60
- s.add_dependency(%q<activerecord>, [">= 0"])
64
+ s.add_dependency(%q<activerecord>, [">= 4.0.0"])
61
65
  s.add_dependency(%q<activesupport>, [">= 0"])
62
66
  s.add_dependency(%q<i18n>, [">= 0"])
63
67
  s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
64
68
  end
65
69
  else
66
- s.add_dependency(%q<activerecord>, [">= 0"])
70
+ s.add_dependency(%q<activerecord>, [">= 4.0.0"])
67
71
  s.add_dependency(%q<activesupport>, [">= 0"])
68
72
  s.add_dependency(%q<i18n>, [">= 0"])
69
73
  s.add_dependency(%q<jeweler>, ["~> 1.8.0"])