translatable 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,4 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
- bundler_args: --without=debug
5
+ bundler_args: --without=debug development
data/Gemfile CHANGED
@@ -5,22 +5,31 @@ gem "activesupport", :require => false
5
5
  gem "i18n"
6
6
 
7
7
  group :debug do
8
- gem "simplecov", ">= 0.6.0", :platform => :ruby_19
9
- gem "debugger", "~> 1.1.3", :platform => :ruby_19
8
+ gem "debugger", "~> 1.2.2", :platform => :ruby_19
10
9
  gem "ruby-debug", :platform => :ruby_18
11
10
  end
12
11
 
13
12
  group :development do
14
- gem "yard"
15
- gem "jeweler", ">= 1.6.0"
16
- gem "bundler", ">= 1.2.0"
13
+ gem "jeweler", "~> 1.8.0"
14
+ end
15
+
16
+ group :debug, :test do
17
+ gem "yard"
18
+ gem "redcarpet"
19
+
20
+ gem "simplecov", "~> 0.7.1", :require => false, :platform => :ruby_19
21
+ gem "rcov", "~> 1.0.0", :require => false, :platform => :ruby_18
17
22
  end
18
23
 
19
24
  group :test do
25
+ gem "sqlite3"
26
+ gem "database_cleaner"
27
+
20
28
  gem "rails"
29
+
30
+ gem 'minitest'
21
31
  gem "test-unit"
22
32
  gem "shoulda"
23
33
 
24
- gem "database_cleaner"
25
- gem "sqlite3"
26
- end
34
+ gem "turn"
35
+ end
@@ -29,25 +29,27 @@ GEM
29
29
  activesupport (= 3.1.8)
30
30
  activesupport (3.1.8)
31
31
  multi_json (>= 1.0, < 1.3)
32
+ ansi (1.4.3)
32
33
  arel (2.2.3)
33
34
  builder (3.0.0)
34
35
  columnize (0.3.6)
35
36
  database_cleaner (0.7.2)
36
- debugger (1.1.4)
37
+ debugger (1.2.4)
37
38
  columnize (>= 0.3.1)
38
39
  debugger-linecache (~> 1.1.1)
39
- debugger-ruby_core_source (~> 1.1.3)
40
+ debugger-ruby_core_source (~> 1.1.7)
40
41
  debugger-linecache (1.1.2)
41
42
  debugger-ruby_core_source (>= 1.1.1)
42
- debugger-ruby_core_source (1.1.3)
43
+ debugger-ruby_core_source (1.1.9)
43
44
  erubis (2.7.0)
44
45
  git (1.2.5)
45
46
  hike (1.2.1)
46
47
  i18n (0.6.0)
47
- jeweler (1.6.4)
48
+ jeweler (1.8.4)
48
49
  bundler (~> 1.0)
49
50
  git (>= 1.2.5)
50
51
  rake
52
+ rdoc
51
53
  json (1.7.5)
52
54
  linecache (0.46)
53
55
  rbx-require-relative (> 0.0.4)
@@ -56,6 +58,7 @@ GEM
56
58
  mime-types (~> 1.16)
57
59
  treetop (~> 1.4.8)
58
60
  mime-types (1.19)
61
+ minitest (4.6.2)
59
62
  multi_json (1.2.0)
60
63
  polyglot (0.3.3)
61
64
  rack (1.3.6)
@@ -84,8 +87,10 @@ GEM
84
87
  thor (~> 0.14.6)
85
88
  rake (0.9.2.2)
86
89
  rbx-require-relative (0.0.9)
90
+ rcov (1.0.0)
87
91
  rdoc (3.12)
88
92
  json (~> 1.4)
93
+ redcarpet (2.2.2)
89
94
  ruby-debug (0.10.4)
90
95
  columnize (>= 0.1)
91
96
  ruby-debug-base (~> 0.10.4.0)
@@ -97,10 +102,10 @@ GEM
97
102
  shoulda-context (1.0.1)
98
103
  shoulda-matchers (1.4.1)
99
104
  activesupport (>= 3.0.0)
100
- simplecov (0.6.4)
105
+ simplecov (0.7.1)
101
106
  multi_json (~> 1.0)
102
- simplecov-html (~> 0.5.3)
103
- simplecov-html (0.5.3)
107
+ simplecov-html (~> 0.7.1)
108
+ simplecov-html (0.7.1)
104
109
  sprockets (2.0.4)
105
110
  hike (~> 1.2)
106
111
  rack (~> 1.0)
@@ -112,6 +117,8 @@ GEM
112
117
  treetop (1.4.12)
113
118
  polyglot
114
119
  polyglot (>= 0.3.1)
120
+ turn (0.9.6)
121
+ ansi
115
122
  tzinfo (0.3.33)
116
123
  yard (0.6.8)
117
124
 
@@ -121,15 +128,18 @@ PLATFORMS
121
128
  DEPENDENCIES
122
129
  activerecord
123
130
  activesupport
124
- bundler (>= 1.2.0)
125
131
  database_cleaner
126
- debugger (~> 1.1.3)
132
+ debugger (~> 1.2.2)
127
133
  i18n
128
- jeweler (>= 1.6.0)
134
+ jeweler (~> 1.8.0)
135
+ minitest
129
136
  rails
137
+ rcov (~> 1.0.0)
138
+ redcarpet
130
139
  ruby-debug
131
140
  shoulda
132
- simplecov (>= 0.6.0)
141
+ simplecov (~> 0.7.1)
133
142
  sqlite3
134
143
  test-unit
144
+ turn
135
145
  yard
@@ -167,6 +167,10 @@ An example of application:
167
167
  news.content
168
168
  # => "That is where the text goes"
169
169
 
170
+ == Testing
171
+
172
+ Run the tests with `VERBOSE=true` to see SQL queries
173
+
170
174
  == Contributing to translatable
171
175
 
172
176
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/Rakefile CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'bundler'
5
+ require 'rake'
6
+ require 'rake/testtask'
7
+
5
8
  begin
6
9
  Bundler.setup(:default, :development)
7
10
  rescue Bundler::BundlerError => e
@@ -9,25 +12,27 @@ rescue Bundler::BundlerError => e
9
12
  $stderr.puts "Run `bundle install` to install missing gems"
10
13
  exit e.status_code
11
14
  end
12
- require 'rake'
13
15
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "translatable"
18
- gem.homepage = "http://github.com/kot-begemot/translatable"
19
- gem.license = "MIT"
20
- gem.summary = %Q{An esay way to manage the translations for datamapper}
21
- gem.description = %Q{This game was build to make whole proccess of working with translation for DM to be almost invisble. That was THE AIM.}
22
- gem.email = "max@studentify.nl"
23
- gem.authors = ["E-Max"]
24
- # dependencies defined in Gemfile
16
+ begin
17
+ require 'jeweler'
18
+ Jeweler::Tasks.new do |gem|
19
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
20
+ gem.name = "translatable"
21
+ gem.homepage = "http://github.com/kot-begemot/translatable"
22
+ gem.license = "MIT"
23
+ gem.summary = %Q{An esay way to manage the translations for datamapper}
24
+ gem.description = %Q{This game was build to make whole proccess of working with translation for DM to be almost invisble. That was THE AIM.}
25
+ gem.email = "max@studentify.nl"
26
+ gem.authors = ["E-Max"]
27
+ # dependencies defined in Gemfile
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+ rescue LoadError
31
+ $stderr.puts "Skip jeweler loading..."
25
32
  end
26
- Jeweler::RubygemsDotOrgTasks.new
27
33
 
28
- require 'rake/testtask'
29
34
  Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
35
+ test.libs += ['lib', 'test']
31
36
  test.pattern = 'test/**/*_test.rb'
32
37
  test.verbose = true
33
38
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,7 +5,7 @@ module Translatable
5
5
  class TranslationGenerator < Rails::Generators::NamedBase
6
6
  include Translatable::GeneratorHelper
7
7
 
8
- desc "Creates ActiveRecord for translation dealer"
8
+ desc "Creates ActiveRecord for translation"
9
9
 
10
10
  class_option :prefix, :type => :string, :default => "translatable", :desc => "Specifies the prefix to used tof translation dealer (Default: translatable)"
11
11
  class_option :origin, :type => :string, :default => "origin", :desc => "Specifies the association name to be use for origin (Default: origin)"
@@ -30,9 +30,9 @@ module Translatable
30
30
  # should be avoided.
31
31
  # In later gem version its existance might not be necessary.
32
32
  CONTENT
33
- unless attributes.empty?
34
- block << " attr_accessible :#{attributes.map(&:name).join(", :")}\n"
35
- end
33
+ # unless attributes.empty?
34
+ # block << " attr_accessible :#{attributes.map(&:name).join(", :")}\n"
35
+ # end
36
36
  block << " #attr_protected :#{options[:origin]}_id, :#{options[:locale]}\n"
37
37
  block
38
38
  end
@@ -4,13 +4,15 @@ if defined?(Rails)
4
4
  require 'translatable/engine'
5
5
 
6
6
  ActiveSupport.on_load(:active_record) do
7
- ActiveSupport.on_load(:i18n) do
8
- ActiveRecord::Base.extend Translatable::ActiveRecord
9
- end
7
+ ActiveRecord::Base.extend Translatable::ActiveRecord if defined?(I18n)
10
8
  end
11
9
  else
12
- require 'active_record'
13
- require 'i18n'
14
-
15
- ActiveRecord::Base.extend Translatable::ActiveRecord
10
+ begin
11
+ require 'active_record'
12
+ require 'i18n'
13
+
14
+ ActiveRecord::Base.extend Translatable::ActiveRecord
15
+ rescue LoadError
16
+ $stderr.puts "Warning: Translatable is not loaded"
17
+ end
16
18
  end
@@ -200,7 +200,7 @@ module Translatable
200
200
 
201
201
  self.module_eval <<-RUBY, __FILE__, __LINE__ + 1
202
202
  def translatable_set_current(locale = ::I18n.locale)
203
- locale = locale.to_s
203
+ locale = @translatable_locale = locale.to_s
204
204
  @current_translation = if translations.loaded?
205
205
  translations.select { |t| t.send(:"#{@translatable[:locale]}") == locale }
206
206
  else
@@ -5,6 +5,10 @@ require 'support/models/posts'
5
5
  require 'support/models/messages'
6
6
 
7
7
  class TranslatableTest < Test::Unit::TestCase
8
+ teardown do
9
+ ::I18n.locale = ::I18n.default_locale
10
+ end
11
+
8
12
  context "Translatable hash" do
9
13
  should "Define default" do
10
14
  th = News.instance_variable_get :@translatable
@@ -54,9 +58,10 @@ class TranslatableTest < Test::Unit::TestCase
54
58
 
55
59
  t_news = TranslatableNews.last
56
60
  assert_equal [t_news], news.other_translations
57
- ::I18n.locale = :ru
61
+
62
+ news.set_current_translation :ru
63
+
58
64
  assert_equal [], news.other_translations
59
- ::I18n.locale = ::I18n.default_locale
60
65
  end
61
66
 
62
67
  should "Provide errors on creation" do
@@ -154,9 +159,9 @@ class TranslatableTest < Test::Unit::TestCase
154
159
  assert news.persisted?
155
160
 
156
161
  ::I18n.locale = :ru
162
+
157
163
  assert_equal "Заголовок", news.title
158
164
  assert_equal "Содержание", news.content
159
- ::I18n.locale = ::I18n.default_locale
160
165
  end
161
166
 
162
167
  should "Not been set if unavailable" do
@@ -164,13 +169,13 @@ class TranslatableTest < Test::Unit::TestCase
164
169
  {:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
165
170
 
166
171
  assert news.persisted?
172
+ news.set_current_translation :de
167
173
 
168
- ::I18n.locale = :de
169
174
  assert_nil news.title
170
175
  assert_nil news.content
171
176
  end
172
177
 
173
- should "Be be switched on locale switching" do
178
+ should "Be switched on locale switching" do
174
179
  news = News.create :translations_attributes => [{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
175
180
 
176
181
  assert news.persisted?
@@ -183,7 +188,7 @@ class TranslatableTest < Test::Unit::TestCase
183
188
  assert_equal "Resent News", news.title
184
189
  assert_equal "That is where the text goes", news.content
185
190
 
186
- ::I18n.locale = :ru
191
+ news.set_current_translation :ru
187
192
 
188
193
  assert_equal "Заголовок", news.title
189
194
  assert_equal "Содержание", news.content
@@ -240,9 +245,9 @@ class TranslatableTest < Test::Unit::TestCase
240
245
 
241
246
  assert_equal "Resent Post", post.translated_title
242
247
 
243
- ::I18n.locale = :ru
248
+ post.set_current_translation :ru
249
+
244
250
  assert_equal "Заголовок", post.translated_title
245
- ::I18n.locale = ::I18n.default_locale
246
251
  end
247
252
 
248
253
  context "Mass assigment" do
@@ -16,7 +16,6 @@ class TranslatableArticle < 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
- attr_accessible :title, :content
20
19
  #attr_protected :origin_id, :locale
21
20
  end
22
21
  CONTENT
@@ -43,7 +42,6 @@ class TranslationArticle < ActiveRecord::Base
43
42
  # This class deals purely with translations themselves. Hence, any edition of
44
43
  # should be avoided.
45
44
  # In later gem version its existance might not be necessary.
46
- attr_accessible :title, :content
47
45
  #attr_protected :post_id, :language
48
46
  end
49
47
  CONTENT
@@ -5,6 +5,8 @@ ActiveRecord::Base.establish_connection(
5
5
  :database => ':memory:'
6
6
  )
7
7
 
8
+ $VERBOSE ||= ENV['VERBOSE'] == 'true'
9
+
8
10
  ActiveRecord::Migration.verbose = $VERBOSE
9
11
  if $VERBOSE
10
12
  ActiveRecord::Base.logger = Logger.new(STDOUT)
@@ -5,7 +5,10 @@ require "i18n"
5
5
 
6
6
  begin
7
7
  require 'simplecov'
8
- SimpleCov.start
8
+ SimpleCov.start do
9
+ add_filter "/test/"
10
+ add_filter "/vendor/"
11
+ end
9
12
  rescue LoadError
10
13
  $stderr.puts "Simplecov is skipped"
11
14
  end
@@ -18,13 +21,19 @@ rescue Bundler::BundlerError => e
18
21
  exit e.status_code
19
22
  end
20
23
 
21
- $LOAD_PATH.unshift(File.dirname(__FILE__))
22
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
23
24
  require 'translatable'
24
25
 
25
26
  require File.expand_path("support/active_record", File.dirname(__FILE__))
26
27
  require File.expand_path("support/database_cleaner", File.dirname(__FILE__))
27
28
 
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
+
28
37
  class Test::Unit::TestCase
29
38
  include OrmSetup
30
39
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "translatable"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
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-06"
12
+ s.date = "2013-03-16"
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 = [
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".rvmrc",
22
21
  ".travis.yml",
23
22
  "Gemfile",
24
23
  "Gemfile.lock",
@@ -56,24 +55,18 @@ Gem::Specification.new do |s|
56
55
  s.add_runtime_dependency(%q<activerecord>, [">= 0"])
57
56
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
58
57
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
59
- s.add_development_dependency(%q<yard>, [">= 0"])
60
- s.add_development_dependency(%q<jeweler>, [">= 1.6.0"])
61
- s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
58
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.0"])
62
59
  else
63
60
  s.add_dependency(%q<activerecord>, [">= 0"])
64
61
  s.add_dependency(%q<activesupport>, [">= 0"])
65
62
  s.add_dependency(%q<i18n>, [">= 0"])
66
- s.add_dependency(%q<yard>, [">= 0"])
67
- s.add_dependency(%q<jeweler>, [">= 1.6.0"])
68
- s.add_dependency(%q<bundler>, [">= 1.2.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
69
64
  end
70
65
  else
71
66
  s.add_dependency(%q<activerecord>, [">= 0"])
72
67
  s.add_dependency(%q<activesupport>, [">= 0"])
73
68
  s.add_dependency(%q<i18n>, [">= 0"])
74
- s.add_dependency(%q<yard>, [">= 0"])
75
- s.add_dependency(%q<jeweler>, [">= 1.6.0"])
76
- s.add_dependency(%q<bundler>, [">= 1.2.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.8.0"])
77
70
  end
78
71
  end
79
72
 
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.3.0
4
+ version: 0.3.1
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-06 00:00:00.000000000Z
12
+ date: 2013-03-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &76461280 !ruby/object:Gem::Requirement
16
+ requirement: &70443110 !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: *76461280
24
+ version_requirements: *70443110
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &76460820 !ruby/object:Gem::Requirement
27
+ requirement: &70441740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *76460820
35
+ version_requirements: *70441740
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &76460440 !ruby/object:Gem::Requirement
38
+ requirement: &70440960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,40 +43,18 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *76460440
47
- - !ruby/object:Gem::Dependency
48
- name: yard
49
- requirement: &76460090 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: *76460090
46
+ version_requirements: *70440960
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: jeweler
60
- requirement: &76459550 !ruby/object:Gem::Requirement
49
+ requirement: &70598430 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: 1.6.0
66
- type: :development
67
- prerelease: false
68
- version_requirements: *76459550
69
- - !ruby/object:Gem::Dependency
70
- name: bundler
71
- requirement: &76459150 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ! '>='
52
+ - - ~>
75
53
  - !ruby/object:Gem::Version
76
- version: 1.2.0
54
+ version: 1.8.0
77
55
  type: :development
78
56
  prerelease: false
79
- version_requirements: *76459150
57
+ version_requirements: *70598430
80
58
  description: This game was build to make whole proccess of working with translation
81
59
  for DM to be almost invisble. That was THE AIM.
82
60
  email: max@studentify.nl
@@ -87,7 +65,6 @@ extra_rdoc_files:
87
65
  - README.rdoc
88
66
  files:
89
67
  - .document
90
- - .rvmrc
91
68
  - .travis.yml
92
69
  - Gemfile
93
70
  - Gemfile.lock
@@ -126,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
103
  version: '0'
127
104
  segments:
128
105
  - 0
129
- hash: -331493043
106
+ hash: -740240291
130
107
  required_rubygems_version: !ruby/object:Gem::Requirement
131
108
  none: false
132
109
  requirements:
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use --create 1.9.2@translatable