simple_model_translations 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,8 +17,9 @@ module SimpleModelTranslations
17
17
  # class Post < ActiveRecord::Base
18
18
  # translates :title, :description, :attributes => true
19
19
  # end
20
- def translates(*attributes)
20
+ def translates(*attributes, &block)
21
21
  configure_translations(attributes.extract_options!)
22
+ translation_class.class_eval(&block) if block_given?
22
23
 
23
24
  attributes.each do |attribute|
24
25
  # attribute setter
@@ -1,3 +1,3 @@
1
1
  module SimpleModelTranslations
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2.0'
3
3
  end
data/spec/data/models.rb CHANGED
@@ -22,3 +22,9 @@ end
22
22
  class Category < ActiveRecord::Base
23
23
  translates :name, :attributes => true
24
24
  end
25
+
26
+ class Book < ActiveRecord::Base
27
+ translates :name do
28
+ validates_presence_of :name
29
+ end
30
+ end
data/spec/data/schema.rb CHANGED
@@ -45,5 +45,12 @@ ActiveRecord::Schema.define do
45
45
  t.references :some_models
46
46
  t.string :name
47
47
  end
48
+
49
+ create_table :books, :force => true
50
+ create_table :book_translations, :force => true do |t|
51
+ t.string :locale
52
+ t.references :book
53
+ t.string :name
54
+ end
48
55
  end
49
56
 
@@ -12,3 +12,11 @@ describe Post do
12
12
  post.should_not be_valid
13
13
  end
14
14
  end
15
+
16
+ describe Book do
17
+ it 'should validate presence of name' do
18
+ book = Book.new(:locale => :ru, :name => '')
19
+ book.should_not be_valid
20
+ book.errors['translations.name'].should_not be_empty
21
+ end
22
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_model_translations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 9
10
- version: 0.1.9
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pavel Forkert
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-11 00:00:00 +02:00
18
+ date: 2010-11-15 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency