translatable 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/Gemfile +11 -7
- data/Gemfile.lock +73 -5
- data/Rakefile +7 -3
- data/VERSION +1 -1
- data/lib/generators/translatable/model_generator.rb +45 -0
- data/lib/generators/translatable/translation_generator.rb +45 -0
- data/lib/translatable/active_record.rb +254 -0
- data/lib/translatable/engine.rb +6 -0
- data/lib/translatable/generator_helper.rb +20 -0
- data/lib/translatable.rb +13 -258
- data/test/cases/translatable_test.rb +276 -0
- data/test/generators/model_generator_test.rb +97 -0
- data/test/generators/translation_generator_test.rb +71 -0
- data/test/support/active_record.rb +4 -1
- data/test/{messages.rb → support/models/messages.rb} +0 -0
- data/test/{news.rb → support/models/news.rb} +0 -0
- data/test/{posts.rb → support/models/posts.rb} +0 -0
- data/test/{helper.rb → test_helper.rb} +18 -6
- data/translatable.gemspec +20 -16
- metadata +38 -39
- data/test/test_translatable.rb +0 -273
@@ -0,0 +1,71 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "rails"
|
3
|
+
require 'rails/generators'
|
4
|
+
require "generators/translatable/translation_generator"
|
5
|
+
|
6
|
+
class TranslationGeneratorTest < Rails::Generators::TestCase
|
7
|
+
tests Translatable::Generators::TranslationGenerator
|
8
|
+
destination File.expand_path("../../../tmp", __FILE__)
|
9
|
+
setup :prepare_destination
|
10
|
+
teardown :cleanup_destination_root
|
11
|
+
|
12
|
+
should "Create required files (default)" do
|
13
|
+
run_generator %w(article title:string content:string)
|
14
|
+
assert_file "app/models/translatable_article.rb", <<CONTENT
|
15
|
+
class TranslatableArticle < ActiveRecord::Base
|
16
|
+
# This class deals purely with translations themselves. Hence, any edition of
|
17
|
+
# should be avoided.
|
18
|
+
# In later gem version its existance might not be necessary.
|
19
|
+
attr_accessible :title, :content
|
20
|
+
#attr_protected :origin_id, :locale
|
21
|
+
end
|
22
|
+
CONTENT
|
23
|
+
assert_migration "db/migrate/create_translatable_articles.rb", <<CONTENT
|
24
|
+
class CreateTranslatableArticles < ActiveRecord::Migration
|
25
|
+
def change
|
26
|
+
create_table :translatable_articles do |t|
|
27
|
+
t.string :title
|
28
|
+
t.string :content
|
29
|
+
t.integer :origin_id
|
30
|
+
t.string :locale
|
31
|
+
|
32
|
+
t.timestamps
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
CONTENT
|
37
|
+
end
|
38
|
+
|
39
|
+
should "Create required files (with options)" do
|
40
|
+
run_generator %w(article title:string content:string --prefix=Translation --origin=post --locale=language)
|
41
|
+
assert_file "app/models/translation_article.rb", <<CONTENT
|
42
|
+
class TranslationArticle < ActiveRecord::Base
|
43
|
+
# This class deals purely with translations themselves. Hence, any edition of
|
44
|
+
# should be avoided.
|
45
|
+
# In later gem version its existance might not be necessary.
|
46
|
+
attr_accessible :title, :content
|
47
|
+
#attr_protected :post_id, :language
|
48
|
+
end
|
49
|
+
CONTENT
|
50
|
+
assert_migration "db/migrate/create_translation_articles.rb", <<CONTENT
|
51
|
+
class CreateTranslationArticles < ActiveRecord::Migration
|
52
|
+
def change
|
53
|
+
create_table :translation_articles do |t|
|
54
|
+
t.string :title
|
55
|
+
t.string :content
|
56
|
+
t.integer :post_id
|
57
|
+
t.string :language
|
58
|
+
|
59
|
+
t.timestamps
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
CONTENT
|
64
|
+
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
|
68
|
+
def cleanup_destination_root
|
69
|
+
FileUtils.rm_rf destination_root
|
70
|
+
end
|
71
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,9 +1,13 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'bundler'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
require 'test/unit'
|
3
|
+
require "shoulda-context"
|
4
|
+
require "i18n"
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start
|
9
|
+
rescue LoadError
|
10
|
+
$stderr.puts "Simplecov is skipped"
|
7
11
|
end
|
8
12
|
|
9
13
|
begin
|
@@ -13,7 +17,6 @@ rescue Bundler::BundlerError => e
|
|
13
17
|
$stderr.puts "Run `bundle install` to install missing gems"
|
14
18
|
exit e.status_code
|
15
19
|
end
|
16
|
-
require 'test/unit'
|
17
20
|
|
18
21
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
19
22
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
@@ -24,4 +27,13 @@ require File.expand_path("support/database_cleaner", File.dirname(__FILE__))
|
|
24
27
|
|
25
28
|
class Test::Unit::TestCase
|
26
29
|
include OrmSetup
|
30
|
+
|
31
|
+
setup do
|
32
|
+
before_setup
|
33
|
+
::I18n.locale = ::I18n.default_locale
|
34
|
+
end
|
35
|
+
|
36
|
+
teardown do
|
37
|
+
after_teardown
|
38
|
+
end
|
27
39
|
end
|
data/translatable.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "translatable"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["E-Max"]
|
12
|
-
s.date = "2013-03-
|
12
|
+
s.date = "2013-03-06"
|
13
13
|
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
14
|
s.email = "max@studentify.nl"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,14 +26,21 @@ Gem::Specification.new do |s|
|
|
26
26
|
"README.rdoc",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
|
+
"lib/generators/translatable/model_generator.rb",
|
30
|
+
"lib/generators/translatable/translation_generator.rb",
|
29
31
|
"lib/translatable.rb",
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"test/
|
32
|
+
"lib/translatable/active_record.rb",
|
33
|
+
"lib/translatable/engine.rb",
|
34
|
+
"lib/translatable/generator_helper.rb",
|
35
|
+
"test/cases/translatable_test.rb",
|
36
|
+
"test/generators/model_generator_test.rb",
|
37
|
+
"test/generators/translation_generator_test.rb",
|
34
38
|
"test/support/active_record.rb",
|
35
39
|
"test/support/database_cleaner.rb",
|
36
|
-
"test/
|
40
|
+
"test/support/models/messages.rb",
|
41
|
+
"test/support/models/news.rb",
|
42
|
+
"test/support/models/posts.rb",
|
43
|
+
"test/test_helper.rb",
|
37
44
|
"translatable.gemspec"
|
38
45
|
]
|
39
46
|
s.homepage = "http://github.com/kot-begemot/translatable"
|
@@ -47,29 +54,26 @@ Gem::Specification.new do |s|
|
|
47
54
|
|
48
55
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
56
|
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
50
58
|
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
51
59
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
52
60
|
s.add_development_dependency(%q<jeweler>, [">= 1.6.0"])
|
53
|
-
s.add_development_dependency(%q<bundler>, [">= 1.
|
54
|
-
s.add_development_dependency(%q<simplecov>, [">= 0.6.0"])
|
55
|
-
s.add_development_dependency(%q<rcov>, [">= 1.0.0"])
|
61
|
+
s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
|
56
62
|
else
|
57
63
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
64
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
58
65
|
s.add_dependency(%q<i18n>, [">= 0"])
|
59
66
|
s.add_dependency(%q<yard>, [">= 0"])
|
60
67
|
s.add_dependency(%q<jeweler>, [">= 1.6.0"])
|
61
|
-
s.add_dependency(%q<bundler>, [">= 1.
|
62
|
-
s.add_dependency(%q<simplecov>, [">= 0.6.0"])
|
63
|
-
s.add_dependency(%q<rcov>, [">= 1.0.0"])
|
68
|
+
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
64
69
|
end
|
65
70
|
else
|
66
71
|
s.add_dependency(%q<activerecord>, [">= 0"])
|
72
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
67
73
|
s.add_dependency(%q<i18n>, [">= 0"])
|
68
74
|
s.add_dependency(%q<yard>, [">= 0"])
|
69
75
|
s.add_dependency(%q<jeweler>, [">= 1.6.0"])
|
70
|
-
s.add_dependency(%q<bundler>, [">= 1.
|
71
|
-
s.add_dependency(%q<simplecov>, [">= 0.6.0"])
|
72
|
-
s.add_dependency(%q<rcov>, [">= 1.0.0"])
|
76
|
+
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
|
-
requirement: &
|
16
|
+
requirement: &76461280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *76461280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
26
|
+
name: activesupport
|
27
|
+
requirement: &76460820 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,62 +32,51 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *76460820
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement: &
|
37
|
+
name: i18n
|
38
|
+
requirement: &76460440 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: '0'
|
44
|
-
type: :
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *85332600
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: jeweler
|
49
|
-
requirement: &85332350 !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ! '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.6.0
|
55
|
-
type: :development
|
44
|
+
type: :runtime
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
46
|
+
version_requirements: *76460440
|
58
47
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
60
|
-
requirement: &
|
48
|
+
name: yard
|
49
|
+
requirement: &76460090 !ruby/object:Gem::Requirement
|
61
50
|
none: false
|
62
51
|
requirements:
|
63
52
|
- - ! '>='
|
64
53
|
- !ruby/object:Gem::Version
|
65
|
-
version:
|
54
|
+
version: '0'
|
66
55
|
type: :development
|
67
56
|
prerelease: false
|
68
|
-
version_requirements: *
|
57
|
+
version_requirements: *76460090
|
69
58
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: &
|
59
|
+
name: jeweler
|
60
|
+
requirement: &76459550 !ruby/object:Gem::Requirement
|
72
61
|
none: false
|
73
62
|
requirements:
|
74
63
|
- - ! '>='
|
75
64
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
65
|
+
version: 1.6.0
|
77
66
|
type: :development
|
78
67
|
prerelease: false
|
79
|
-
version_requirements: *
|
68
|
+
version_requirements: *76459550
|
80
69
|
- !ruby/object:Gem::Dependency
|
81
|
-
name:
|
82
|
-
requirement: &
|
70
|
+
name: bundler
|
71
|
+
requirement: &76459150 !ruby/object:Gem::Requirement
|
83
72
|
none: false
|
84
73
|
requirements:
|
85
74
|
- - ! '>='
|
86
75
|
- !ruby/object:Gem::Version
|
87
|
-
version: 1.
|
76
|
+
version: 1.2.0
|
88
77
|
type: :development
|
89
78
|
prerelease: false
|
90
|
-
version_requirements: *
|
79
|
+
version_requirements: *76459150
|
91
80
|
description: This game was build to make whole proccess of working with translation
|
92
81
|
for DM to be almost invisble. That was THE AIM.
|
93
82
|
email: max@studentify.nl
|
@@ -106,14 +95,21 @@ files:
|
|
106
95
|
- README.rdoc
|
107
96
|
- Rakefile
|
108
97
|
- VERSION
|
98
|
+
- lib/generators/translatable/model_generator.rb
|
99
|
+
- lib/generators/translatable/translation_generator.rb
|
109
100
|
- lib/translatable.rb
|
110
|
-
-
|
111
|
-
-
|
112
|
-
-
|
113
|
-
- test/
|
101
|
+
- lib/translatable/active_record.rb
|
102
|
+
- lib/translatable/engine.rb
|
103
|
+
- lib/translatable/generator_helper.rb
|
104
|
+
- test/cases/translatable_test.rb
|
105
|
+
- test/generators/model_generator_test.rb
|
106
|
+
- test/generators/translation_generator_test.rb
|
114
107
|
- test/support/active_record.rb
|
115
108
|
- test/support/database_cleaner.rb
|
116
|
-
- test/
|
109
|
+
- test/support/models/messages.rb
|
110
|
+
- test/support/models/news.rb
|
111
|
+
- test/support/models/posts.rb
|
112
|
+
- test/test_helper.rb
|
117
113
|
- translatable.gemspec
|
118
114
|
homepage: http://github.com/kot-begemot/translatable
|
119
115
|
licenses:
|
@@ -128,6 +124,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
124
|
- - ! '>='
|
129
125
|
- !ruby/object:Gem::Version
|
130
126
|
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: -331493043
|
131
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
131
|
none: false
|
133
132
|
requirements:
|
data/test/test_translatable.rb
DELETED
@@ -1,273 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
require 'news'
|
4
|
-
require 'posts'
|
5
|
-
require 'messages'
|
6
|
-
|
7
|
-
class TestDmTranslatable < Test::Unit::TestCase
|
8
|
-
|
9
|
-
def setup
|
10
|
-
before_setup
|
11
|
-
end
|
12
|
-
|
13
|
-
def teardown
|
14
|
-
after_teardown
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_translatable_hash_is_defined
|
18
|
-
th = News.instance_variable_get :@translatable
|
19
|
-
|
20
|
-
assert_kind_of Hash, th
|
21
|
-
assert th.has_key?(:properties)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_translatable_hash_has_default_model
|
25
|
-
assert_equal ::TranslatableNews, News.send(:translatable_model_prepared, 'TranslatableNews')
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_translatable_assepts_constant_as_model
|
29
|
-
assert_equal ::TranslatableNews, News.send(:translatable_model_prepared, ::TranslatableNews)
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_translatable_assepts_sting_as_model
|
33
|
-
assert_equal ::TranslatableNews, News.send(:translatable_model_prepared, "TranslatableNews")
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_translatable_assepts_symbol_as_model
|
37
|
-
assert_equal ::TranslatableNews, News.send(:translatable_model_prepared, :TranslatableNews)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_instance_respond_to_translatable_methods
|
41
|
-
news = News.new
|
42
|
-
|
43
|
-
assert news.respond_to?(:title), "title methods is missing for News instance"
|
44
|
-
assert news.respond_to?(:content), "content methods is missing for News instance"
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_translated_instance_has_translatable_methods
|
48
|
-
news = TranslatableNews.new
|
49
|
-
|
50
|
-
assert news.respond_to?(:title), "Title method is missing for TranslatableNews instance"
|
51
|
-
assert news.respond_to?(:content), "Content method is missing for TranslatableNews instance"
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_translated_instance_has_relation_to_origin
|
55
|
-
news = TranslatableNews.new
|
56
|
-
|
57
|
-
assert news.respond_to?(:locale), "Locale method is missing for TranslatableNews instance"
|
58
|
-
assert news.respond_to?(:origin_id), "Origin methods is missing for TranslatableNews instance"
|
59
|
-
assert news.respond_to?(:origin), "Origin methods is missing for TranslatableNews instance"
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_create_without_translation
|
63
|
-
news = News.create
|
64
|
-
|
65
|
-
assert news.persisted?
|
66
|
-
assert_nil TranslatableNews.last
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_create_translated_with_translation
|
70
|
-
news = News.create
|
71
|
-
t_news = TranslatableNews.create :title => "Заголовок", :content => "Содержание", :locale => "ru", :origin_id => news.id
|
72
|
-
|
73
|
-
assert t_news.persisted?
|
74
|
-
|
75
|
-
t_news = TranslatableNews.last
|
76
|
-
assert_equal news.id, t_news.origin_id
|
77
|
-
assert_equal "Заголовок", t_news.title
|
78
|
-
assert_equal "Содержание", t_news.content
|
79
|
-
assert_equal "ru", t_news.locale
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_create_with_translation
|
83
|
-
news = News.create :translations_attributes => [{ :title => "Заголовок", :content => "Содержание", :locale => "ru"}]
|
84
|
-
|
85
|
-
assert news.persisted?
|
86
|
-
|
87
|
-
t_news = TranslatableNews.last
|
88
|
-
assert_equal news.id, t_news.origin_id.to_i
|
89
|
-
assert_equal "Заголовок", t_news.title
|
90
|
-
assert_equal "Содержание", t_news.content
|
91
|
-
assert_equal "ru", t_news.locale
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_no_other_translations
|
95
|
-
news = News.create :translations_attributes => [{ :title => "Заголовок", :content => "Содержание", :locale => "ru"}]
|
96
|
-
|
97
|
-
assert news.persisted?
|
98
|
-
|
99
|
-
t_news = TranslatableNews.last
|
100
|
-
assert_equal [t_news], news.other_translations
|
101
|
-
::I18n.locale = :ru
|
102
|
-
assert_equal [], news.other_translations
|
103
|
-
::I18n.locale = ::I18n.default_locale
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_create_with_translation_with_multiple_locales
|
107
|
-
news = News.create :translations_attributes => [{ :title => "Заголовок", :content => "Содержание", :locale => "ru"},
|
108
|
-
{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
|
109
|
-
|
110
|
-
assert news.persisted?
|
111
|
-
|
112
|
-
t_news = TranslatableNews.first
|
113
|
-
assert_equal news.id, t_news.origin_id.to_i
|
114
|
-
assert_equal "Заголовок", t_news.title
|
115
|
-
assert_equal "Содержание", t_news.content
|
116
|
-
assert_equal "ru", t_news.locale
|
117
|
-
|
118
|
-
t_news = TranslatableNews.last
|
119
|
-
assert_equal news.id, t_news.origin_id.to_i
|
120
|
-
assert_equal "Resent News", t_news.title
|
121
|
-
assert_equal "That is where the text goes", t_news.content
|
122
|
-
assert_equal "en", t_news.locale
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_access_of_default_translation
|
126
|
-
news = News.create :translations_attributes => [{:title => "Заголовок", :content => "Содержание", :locale => "ru"},
|
127
|
-
{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
|
128
|
-
|
129
|
-
assert news.persisted?
|
130
|
-
|
131
|
-
assert_equal "Resent News", news.title
|
132
|
-
assert_equal "That is where the text goes", news.content
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_access_of_different_translation
|
136
|
-
news = News.create :translations_attributes => [{:title => "Заголовок", :content => "Содержание", :locale => "ru"},
|
137
|
-
{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
|
138
|
-
|
139
|
-
assert news.persisted?
|
140
|
-
|
141
|
-
::I18n.locale = :ru
|
142
|
-
assert_equal "Заголовок", news.title
|
143
|
-
assert_equal "Содержание", news.content
|
144
|
-
::I18n.locale = ::I18n.default_locale
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_adding_the_translation
|
148
|
-
news = News.create :translations_attributes => [{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
|
149
|
-
|
150
|
-
assert news.persisted?
|
151
|
-
|
152
|
-
t_news = news.translations.create :title => "Заголовок", :content => "Содержание",:locale => "ru"
|
153
|
-
|
154
|
-
assert t_news.persisted?
|
155
|
-
assert t_news.persisted?
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_getting_different_translations
|
159
|
-
news = News.create :translations_attributes => [{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
|
160
|
-
|
161
|
-
assert news.persisted?
|
162
|
-
|
163
|
-
t_news = news.translations.create :title => "Заголовок", :content => "Содержание",:locale => "ru"
|
164
|
-
assert t_news.persisted?
|
165
|
-
|
166
|
-
::I18n.locale = ::I18n.default_locale
|
167
|
-
|
168
|
-
assert_equal "Resent News", news.title
|
169
|
-
assert_equal "That is where the text goes", news.content
|
170
|
-
|
171
|
-
::I18n.locale = :ru
|
172
|
-
|
173
|
-
assert_equal "Заголовок", news.title
|
174
|
-
assert_equal "Содержание", news.content
|
175
|
-
::I18n.locale = ::I18n.default_locale
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_access_unexisting_translation
|
179
|
-
news = News.create :translations_attributes => [{:title => "Заголовок", :content => "Содержание", :locale => "ru"},
|
180
|
-
{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
|
181
|
-
|
182
|
-
assert news.persisted?
|
183
|
-
|
184
|
-
::I18n.locale = :de
|
185
|
-
assert_nil news.title
|
186
|
-
assert_nil news.content
|
187
|
-
::I18n.locale = ::I18n.default_locale
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_errors_on_translation_creation
|
191
|
-
news = News.create :translations_attributes => [{:title => "Заголовок", :content => "Содержание", :locale => "ru"},
|
192
|
-
{:title => "Resent News", :content => "That is where the text goes", :locale => ""}]
|
193
|
-
|
194
|
-
assert news.new_record?
|
195
|
-
|
196
|
-
assert_equal ["Translations locale can't be blank"], news.errors.full_messages
|
197
|
-
|
198
|
-
news.translations.each do |t|
|
199
|
-
assert t.new_record?
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_validations_are_defined
|
204
|
-
post = Post.create :translations_attributes => [{:title => "Заголовок",:content => "Содержание", :locale => "ru"},
|
205
|
-
{:title => "Resent Post", :content => "That is where the text goes", :locale => "en"}]
|
206
|
-
assert post.persisted?, "Message had errors: #{post.errors.inspect}"
|
207
|
-
|
208
|
-
post = Post.create :translations_attributes => [{:content => "Содержание", :locale => "ru"},
|
209
|
-
{:title => "Resent Post 2", :content => "That is where the text goes", :locale => "en"}]
|
210
|
-
|
211
|
-
assert post.new_record?, "Message had errors: #{post.errors.full_messages.inspect}"
|
212
|
-
assert_equal ["Translations title can't be blank"], post.errors.full_messages
|
213
|
-
|
214
|
-
post = Post.create :translations_attributes => [{:title => "Заголовок 2", :locale => "ru"},
|
215
|
-
{:title => "Resent Post 3", :content => "That is where the text goes", :locale => "en"}]
|
216
|
-
|
217
|
-
assert post.new_record?, "Message had errors: #{post.errors.full_messages.inspect}"
|
218
|
-
assert_equal ["Translations content can't be blank"], post.errors.full_messages
|
219
|
-
|
220
|
-
post = Post.create :translations_attributes => [{:title => "Заголовок", :content => "Содержание", :locale => "ru"},
|
221
|
-
{:title => "Resent Post 3", :content => "That is where the text goes", :locale => "en"}]
|
222
|
-
|
223
|
-
assert post.new_record?, "Message had errors: #{post.errors.full_messages.inspect}"
|
224
|
-
assert_equal ["Translations title has already been taken"], post.errors.full_messages
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_origin_is_owerwrittent
|
228
|
-
post = Post.create :translations_attributes => [{:title => "Заголовок",:content => "Содержание", :locale => "ru"},
|
229
|
-
{:title => "Resent Post", :content => "That is where the text goes", :locale => "en"}]
|
230
|
-
assert post.persisted?, "Message had errors: #{post.errors.inspect}"
|
231
|
-
|
232
|
-
assert_equal post, post.translations.first.post
|
233
|
-
end
|
234
|
-
|
235
|
-
def test_attr_as
|
236
|
-
post = Post.create :translations_attributes => [{:title => "Заголовок",:content => "Содержание", :locale => "ru"},
|
237
|
-
{:title => "Resent Post", :content => "That is where the text goes", :locale => "en"}]
|
238
|
-
assert post.persisted?, "Message had errors: #{post.errors.inspect}"
|
239
|
-
|
240
|
-
assert_equal "Resent Post", post.translated_title
|
241
|
-
|
242
|
-
::I18n.locale = :ru
|
243
|
-
assert_equal "Заголовок", post.translated_title
|
244
|
-
::I18n.locale = ::I18n.default_locale
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_protected_mass_assigment
|
248
|
-
tm = TranslatedMessage.new( :title => "Resent Post", :content => "That is where the text goes", :locale => "en", :message_id => 1)
|
249
|
-
|
250
|
-
assert_equal "Resent Post", tm.title
|
251
|
-
assert_equal "That is where the text goes", tm.content
|
252
|
-
assert_equal nil, tm.locale
|
253
|
-
assert_equal nil, tm.message_id
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_protected_editor_mass_assigment
|
257
|
-
tm = TranslatedMessage.new( {:title => "Resent Post", :content => "That is where the text goes", :locale => "en", :message_id => 1}, :as => :editor)
|
258
|
-
|
259
|
-
assert_equal "Resent Post", tm.title
|
260
|
-
assert_equal "That is where the text goes", tm.content
|
261
|
-
assert_equal "en", tm.locale
|
262
|
-
assert_equal nil, tm.message_id
|
263
|
-
end
|
264
|
-
|
265
|
-
def test_accessible_mass_assigment
|
266
|
-
tp = TranslatableNews.new( :title => "Resent News", :content => "That is where the text goes", :locale => "en", :origin_id => 1)
|
267
|
-
|
268
|
-
assert_equal "Resent News", tp.title
|
269
|
-
assert_equal "That is where the text goes", tp.content
|
270
|
-
assert_equal "en", tp.locale
|
271
|
-
assert_equal 1, tp.origin_id
|
272
|
-
end
|
273
|
-
end
|