translated_attributes 0.5.4 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -7,7 +7,8 @@ Usage
7
7
  =====
8
8
  - As Rails plugin `script/plugin install git://github.com/grosser/translated_attributes.git`
9
9
  - As gem `sudo gem install translated_attributes`
10
- - execute MIGRATION
10
+ - generate migrations: `rails generate translated_attributes`(Rails2: [do it by manually](http://github.com/grosser/translated_attributes/blob/master/lib/generators/translated_attributes/templates/migration.rb))
11
+ - `rake db:migrate`
11
12
 
12
13
  Adding attributes:
13
14
  class Product < ActiveRecord::Base
@@ -42,8 +43,13 @@ Options
42
43
  :table_name => 'user_translations', #default is translations
43
44
  :nil_to_blank => true, #return unfound translations as blank strings ('') instead of nil (default false),
44
45
  :translatable_name => 'translated' #name of the associated translatable (Product has_many :translations a Translation belongs_to XXX), default is :translatable
46
+
45
47
  Author
46
48
  ======
49
+
50
+ ###Contributors
51
+ - [Stefano Diem Benatti](http://github.com/teonimesic)
52
+
47
53
  [Michael Grosser](http://pragmatig.wordpress.com)
48
54
  grosser.michael@gmail.com
49
55
  Hereby placed under public domain, do what you want, just do not hold me accountable...
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.5
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates the migration file for TranslatedAttributes.
3
+
4
+ Example:
5
+ rails generate translated_attributes
6
+
7
+ This will create:
8
+ db/migration/<migration step>_add_translations.rb
@@ -0,0 +1,18 @@
1
+ class AddTranslations < ActiveRecord::Migration
2
+ def self.up
3
+ # you can remove the limit/null constrains
4
+ # this is simply my recommended way of setting things up (save + limits needed storage space)
5
+ create_table :translations do |t|
6
+ t.integer :translatable_id, :null=>false
7
+ t.string :translatable_type, :limit=>40, :null=>false
8
+ t.string :language, :limit=>2, :null=>false
9
+ t.string :attribute, :limit=>40, :null=>false
10
+ t.text :text, :null=>false
11
+ end
12
+ add_index :translations, [:translatable_id, :translatable_type]
13
+ end
14
+
15
+ def self.down
16
+ drop_table :translations
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class TranslatedAttributesGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ def self.next_migration_number(dirname)
7
+ Time.now.strftime("%Y%m%d%H%M%S")
8
+ end
9
+
10
+ def create_migration
11
+ template = File.expand_path('../templates/migration.rb', __FILE__)
12
+ migration_template template, 'db/migrate/add_translations.rb'
13
+ end
14
+ end
@@ -75,7 +75,7 @@ module TranslatedAttributes
75
75
 
76
76
  def set_translated_attribute(locale, field, value)
77
77
  old_value = translated_attributes_for(locale)[field]
78
- return if old_value == value
78
+ return if old_value.to_s == value.to_s
79
79
  changed_attributes.merge!("#{field}_in_#{locale}" => old_value)
80
80
  translated_attributes_for(locale)[field] = value
81
81
  @translated_attributes_changed = true
@@ -67,6 +67,24 @@ describe 'Translated attributes' do
67
67
  p.title_in_de = 'abc'
68
68
  p.title.should == 'abc'
69
69
  end
70
+
71
+ it "records a change" do
72
+ p = Product.new
73
+ p.title = 'abc'
74
+ p.send(:changed_attributes).should == {'title_in_en' => nil}
75
+ end
76
+
77
+ it "does not record changes for nil to blank" do
78
+ p = Product.new
79
+ p.title = ''
80
+ p.send(:changed_attributes).should == {}
81
+ end
82
+
83
+ it "does not record changes for unchanged" do
84
+ p = Product.create!(:title_in_en => 'abc')
85
+ p.title = 'abc'
86
+ p.send(:changed_attributes).should == {}
87
+ end
70
88
  end
71
89
 
72
90
  describe 'storing' do
@@ -5,21 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{translated_attributes}
8
- s.version = "0.5.4"
8
+ s.version = "0.5.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-06-07}
12
+ s.date = %q{2010-07-15}
13
13
  s.email = %q{grosser.michael@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
16
16
  ]
17
17
  s.files = [
18
- "MIGRATION",
19
- "README.markdown",
18
+ "README.markdown",
20
19
  "Rakefile",
21
20
  "VERSION",
22
21
  "init.rb",
22
+ "lib/generators/translated_attributes/USAGE",
23
+ "lib/generators/translated_attributes/templates/migration.rb",
24
+ "lib/generators/translated_attributes/translated_attributes_generator.rb",
23
25
  "lib/translated_attributes.rb",
24
26
  "spec/integration_spec.rb",
25
27
  "spec/models.rb",
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 4
9
- version: 0.5.4
8
+ - 5
9
+ version: 0.5.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Grosser
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-07 00:00:00 +02:00
17
+ date: 2010-07-15 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -38,11 +38,13 @@ extensions: []
38
38
  extra_rdoc_files:
39
39
  - README.markdown
40
40
  files:
41
- - MIGRATION
42
41
  - README.markdown
43
42
  - Rakefile
44
43
  - VERSION
45
44
  - init.rb
45
+ - lib/generators/translated_attributes/USAGE
46
+ - lib/generators/translated_attributes/templates/migration.rb
47
+ - lib/generators/translated_attributes/translated_attributes_generator.rb
46
48
  - lib/translated_attributes.rb
47
49
  - spec/integration_spec.rb
48
50
  - spec/models.rb
data/MIGRATION DELETED
@@ -1,18 +0,0 @@
1
- class AddTranslations < ActiveRecord::Migration
2
- def self.up
3
- #you can remove the limit/null constrains
4
- #this is simply my recommended way of setting things up (save + limits needed storage space)
5
- create_table :translations do |t|
6
- t.column :translatable_id, :integer, :null=>false
7
- t.column :translatable_type, :string, :limit=>40, :null=>false
8
- t.column :language, :string, :limit=>2, :null=>false
9
- t.column :attribute, :string, :limit=>40, :null=>false
10
- t.column :text, :text, :null=>false
11
- end
12
- add_index :translations, [:translatable_id, :translatable_type]
13
- end
14
-
15
- def self.down
16
- drop_table :translations
17
- end
18
- end