translatable 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -72,9 +72,10 @@ Block accepts following methods:
72
72
  OR
73
73
  translatable_locale :lang
74
74
 
75
+ translatable_attr_accessible
75
76
  translatable_attr_protected
76
- If this line is set then the attributes :locale and :origin will be protected from
77
- mass-assigment, otherwise they will be available.
77
+ If this line is set then the attributes :locale and :origin will be allowed or protected
78
+ from for mass-assigment.
78
79
 
79
80
  Note: Note sure that this is the best implementation. Would appreciate any better ideas.
80
81
 
@@ -140,6 +141,7 @@ Models:
140
141
  translatable :content, :presence => true
141
142
  translatable_model "TranslatedNews"
142
143
  translatable_origin :origin_id
144
+ translatable_attr_accessible
143
145
  end
144
146
 
145
147
  attr_accessible :author_id, :author
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.2.0
data/lib/translatable.rb CHANGED
@@ -118,7 +118,21 @@ module ActiveRecord
118
118
  # Default: false
119
119
  #
120
120
  def translatable_attr_protected
121
- @translatable[:attr_protected] = true
121
+ @translatable[:attr_accessible] = false
122
+ end
123
+
124
+ ###
125
+ # Will not register the attributes as accessible.
126
+ # IMPORTANT: Translatable block will be evaluated on the model after it
127
+ # was loaded, so it will modify certain thing on final version. Hence this thing is needed.
128
+ # Examples:
129
+ #
130
+ # translatable_attr_protected
131
+ #
132
+ # Default: false
133
+ #
134
+ def translatable_attr_accessible
135
+ @translatable[:attr_accessible] = true
122
136
  end
123
137
 
124
138
  ###
@@ -208,10 +222,14 @@ module ActiveRecord
208
222
  validates :#{@translatable[:locale]}, :uniqueness => { :scope => :#{@translatable[:origin]}_id }
209
223
 
210
224
  belongs_to :#{@translatable[:origin]}, :class_name => "#{self.name}"
211
-
212
- attr_#{!!@translatable[:attr_protected] ? "protected" : "accessible" } :#{@translatable[:locale]}, :#{@translatable[:origin]}_id
213
225
  RUBY
214
226
 
227
+ unless @translatable[:attr_accessible].nil?
228
+ @translatable[:model].module_eval <<-RUBY, __FILE__, __LINE__ + 1
229
+ attr_#{!!@translatable[:attr_accessible] ? "accessible" : "protected" } :#{@translatable[:locale]}, :#{@translatable[:origin]}_id
230
+ RUBY
231
+ end
232
+
215
233
  @translatable[:properties].each do |p|
216
234
  if p.size > 1
217
235
  @translatable[:model].module_eval <<-RUBY, __FILE__, __LINE__ + 1
data/test/messages.rb CHANGED
@@ -41,6 +41,7 @@ end
41
41
 
42
42
  class TranslatedMessage < ActiveRecord::Base
43
43
  attr_accessible :title, :content
44
+ attr_accessible :title, :content, :locale, :as => :editor
44
45
 
45
46
  before_validation :set_default_locale, :if => :writer_id
46
47
  before_create :duplicate_writer_id, :unless => :writer_id
@@ -65,7 +66,6 @@ class Message < ActiveRecord::Base
65
66
  translatable :content, :presence => true
66
67
  translatable_model 'TranslatedMessage'
67
68
  translatable_origin :message
68
- translatable_attr_protected
69
69
  end
70
70
 
71
71
  attr_accessible :writer_id, :writer
data/test/news.rb CHANGED
@@ -52,6 +52,7 @@ class News < ActiveRecord::Base
52
52
  translatable do
53
53
  translatable :title
54
54
  translatable :content
55
+ translatable_attr_accessible
55
56
  end
56
57
 
57
58
  attr_accessible :author_id, :author
data/test/posts.rb CHANGED
@@ -60,6 +60,7 @@ class Post < ActiveRecord::Base
60
60
  translatable :content, :presence => true
61
61
  translatable_model 'TranslatedPost'
62
62
  translatable_origin :post
63
+ translatable_attr_accessible
63
64
  end
64
65
 
65
66
  attr_accessible :writer_id, :writer
@@ -229,6 +229,15 @@ class TestDmTranslatable < Test::Unit::TestCase
229
229
  assert_equal nil, tm.message_id
230
230
  end
231
231
 
232
+ def test_protected_editor_mass_assigment
233
+ tm = TranslatedMessage.new( {:title => "Resent Post", :content => "That is where the text goes", :locale => "en", :message_id => 1}, :as => :editor)
234
+
235
+ assert_equal "Resent Post", tm.title
236
+ assert_equal "That is where the text goes", tm.content
237
+ assert_equal "en", tm.locale
238
+ assert_equal nil, tm.message_id
239
+ end
240
+
232
241
  def test_accessible_mass_assigment
233
242
  tp = TranslatableNews.new( :title => "Resent News", :content => "That is where the text goes", :locale => "en", :origin_id => 1)
234
243
 
data/translatable.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "translatable"
8
- s.version = "0.1.4"
8
+ s.version = "0.2.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"]
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.1.4
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-08-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &74173130 !ruby/object:Gem::Requirement
16
+ requirement: &84919140 !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: *74173130
24
+ version_requirements: *84919140
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: i18n
27
- requirement: &74172880 !ruby/object:Gem::Requirement
27
+ requirement: &84918890 !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: *74172880
35
+ version_requirements: *84918890
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: yard
38
- requirement: &74172640 !ruby/object:Gem::Requirement
38
+ requirement: &84918650 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *74172640
46
+ version_requirements: *84918650
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &74172400 !ruby/object:Gem::Requirement
49
+ requirement: &84918410 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *74172400
57
+ version_requirements: *84918410
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &74172160 !ruby/object:Gem::Requirement
60
+ requirement: &84918150 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *74172160
68
+ version_requirements: *84918150
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &74171880 !ruby/object:Gem::Requirement
71
+ requirement: &84917890 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.6.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *74171880
79
+ version_requirements: *84917890
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rcov
82
- requirement: &74171640 !ruby/object:Gem::Requirement
82
+ requirement: &84917640 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: 1.0.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *74171640
90
+ version_requirements: *84917640
91
91
  description: This game was build to make whole proccess of working with translation
92
92
  for DM to be almost invisble. That was THE AIM.
93
93
  email: max@studentify.nl
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  segments:
132
132
  - 0
133
- hash: -993677265
133
+ hash: 896165331
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  none: false
136
136
  requirements: