symbolize 4.5.0 → 4.5.1
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +3 -1
- data/lib/symbolize.rb +0 -1
- data/lib/symbolize/active_record.rb +178 -170
- data/lib/symbolize/mongoid.rb +80 -68
- data/lib/symbolize/version.rb +1 -1
- data/spec/db/001_create_testing_structure.rb +3 -3
- data/spec/spec_helper.rb +11 -14
- data/spec/symbolize/active_record_spec.rb +120 -121
- data/spec/symbolize/mongoid_spec.rb +125 -129
- metadata +17 -3
data/lib/symbolize/version.rb
CHANGED
@@ -9,7 +9,7 @@ class CreateTestingStructure < ActiveRecord::Migration
|
|
9
9
|
t.boolean :public
|
10
10
|
t.boolean :cool
|
11
11
|
t.string :role
|
12
|
-
t.string :country, :default =>
|
12
|
+
t.string :country, :default => 'pt'
|
13
13
|
t.string :some_attr # used in name collision tests
|
14
14
|
end
|
15
15
|
create_table :user_skills do |t|
|
@@ -21,8 +21,8 @@ class CreateTestingStructure < ActiveRecord::Migration
|
|
21
21
|
t.string :key, :null => false
|
22
22
|
end
|
23
23
|
create_table :permissions do |t|
|
24
|
-
t.string
|
25
|
-
t.string
|
24
|
+
t.string :name, :null => false
|
25
|
+
t.string :kind, :null => false
|
26
26
|
t.integer :lvl, :null => false
|
27
27
|
end
|
28
28
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -10,10 +10,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
10
10
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
11
|
|
12
12
|
require 'i18n'
|
13
|
-
I18n.load_path += Dir[File.join(File.dirname(__FILE__),
|
14
|
-
I18n.default_locale =
|
13
|
+
I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'locales', '*.{rb,yml}')]
|
14
|
+
I18n.default_locale = 'pt'
|
15
15
|
|
16
|
-
if ENV[
|
16
|
+
if ENV['CI']
|
17
17
|
require 'coveralls'
|
18
18
|
Coveralls.wear!
|
19
19
|
end
|
@@ -21,13 +21,13 @@ end
|
|
21
21
|
#
|
22
22
|
# Mongoid
|
23
23
|
#
|
24
|
-
unless ENV[
|
24
|
+
unless ENV['ONLY_AR']
|
25
25
|
|
26
26
|
require 'mongoid'
|
27
27
|
puts "Using Mongoid v#{Mongoid::VERSION}"
|
28
28
|
|
29
29
|
Mongoid.configure do |config|
|
30
|
-
#config.master = Mongo::Connection.new.db("symbolize_test")
|
30
|
+
# config.master = Mongo::Connection.new.db("symbolize_test")
|
31
31
|
config.connect_to('symbolize_test')
|
32
32
|
end
|
33
33
|
|
@@ -40,11 +40,10 @@ unless ENV["ONLY_AR"]
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
43
|
#
|
45
44
|
# ActiveRecord
|
46
45
|
#
|
47
|
-
unless ENV[
|
46
|
+
unless ENV['ONLY_MONGOID']
|
48
47
|
|
49
48
|
require 'active_record'
|
50
49
|
require 'symbolize/active_record'
|
@@ -53,24 +52,22 @@ unless ENV["ONLY_MONGOID"]
|
|
53
52
|
|
54
53
|
ActiveRecord::Base.send :include, Symbolize::ActiveRecord # this is normally done by the railtie
|
55
54
|
|
56
|
-
ActiveRecord::Base.establish_connection(:adapter =>
|
57
|
-
|
55
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') # 'postgresql', :database => 'symbolize_test', :username => 'postgres')
|
58
56
|
|
59
|
-
if ActiveRecord::VERSION::STRING >=
|
60
|
-
ActiveRecord::Migrator.migrate(
|
57
|
+
if ActiveRecord::VERSION::STRING >= '3.1'
|
58
|
+
ActiveRecord::Migrator.migrate('spec/db')
|
61
59
|
else
|
62
|
-
require
|
60
|
+
require 'db/001_create_testing_structure'
|
63
61
|
CreateTestingStructure.migrate(:up)
|
64
62
|
end
|
65
63
|
|
66
|
-
|
67
64
|
# Spec::Runner.configure do |config|
|
68
65
|
# end
|
69
66
|
|
70
67
|
RSpec.configure do |config|
|
71
68
|
|
72
69
|
config.after(:each) do
|
73
|
-
[User, Permission].each
|
70
|
+
[User, Permission].each(&:delete_all)
|
74
71
|
end
|
75
72
|
|
76
73
|
end
|
@@ -7,21 +7,21 @@ class User < ActiveRecord::Base
|
|
7
7
|
symbolize :other
|
8
8
|
symbolize :language, :in => [:pt, :en]
|
9
9
|
symbolize :sex, :in => [true, false], :scopes => true
|
10
|
-
symbolize :status
|
10
|
+
symbolize :status, :in => [:active, :inactive], :i18n => false, :capitalize => true, :scopes => :shallow, :methods => true
|
11
11
|
symbolize :so, :allow_blank => true, :in => {
|
12
12
|
:linux => 'Linux',
|
13
|
-
:mac
|
14
|
-
:win
|
15
|
-
},
|
13
|
+
:mac => 'Mac OS X',
|
14
|
+
:win => 'Videogame',
|
15
|
+
}, :scopes => true
|
16
16
|
symbolize :gui, :allow_blank => true, :in => [:cocoa, :qt, :gtk], :i18n => false
|
17
|
-
symbolize :karma, :in => %w
|
17
|
+
symbolize :karma, :in => %w(good bad ugly), :methods => true, :i18n => false, :allow_nil => true
|
18
18
|
symbolize :cool, :in => [true, false], :scopes => true
|
19
19
|
|
20
20
|
symbolize :role, :in => [:reader, :writer, :some_existing_attr], :i18n => false, :methods => true, :default => :reader
|
21
21
|
symbolize :country, :in => [:us, :gb, :pt, :ru], :capitalize => true, :i18n => false # note: the default value is provided in db migration
|
22
22
|
|
23
|
-
has_many :extras, :dependent => :destroy, :class_name =>
|
24
|
-
has_many :access, :dependent => :destroy, :class_name =>
|
23
|
+
has_many :extras, :dependent => :destroy, :class_name => 'UserExtra'
|
24
|
+
has_many :access, :dependent => :destroy, :class_name => 'UserAccess'
|
25
25
|
end
|
26
26
|
|
27
27
|
class UserSkill < ActiveRecord::Base
|
@@ -35,48 +35,48 @@ end
|
|
35
35
|
class Permission < ActiveRecord::Base
|
36
36
|
validates_presence_of :name
|
37
37
|
symbolize :kind, :in => [:temp, :perm], :default => :perm
|
38
|
-
symbolize :lvl, :in => (1..9).to_a, :i18n => false
|
38
|
+
symbolize :lvl, :in => (1..9).to_a, :i18n => false # , :default => 1
|
39
39
|
end
|
40
40
|
|
41
41
|
class PermissionSubclass < Permission
|
42
42
|
symbolize :sub_lvl
|
43
43
|
end
|
44
44
|
|
45
|
-
describe
|
45
|
+
describe 'Symbolize' do
|
46
46
|
|
47
|
-
it
|
47
|
+
it 'should respond to symbolize' do
|
48
48
|
expect(ActiveRecord::Base).to respond_to :symbolize
|
49
49
|
end
|
50
50
|
|
51
|
-
it
|
51
|
+
it 'should have a valid blueprint' do
|
52
52
|
# Test records
|
53
|
-
u = User.create(:name => 'Bob'
|
53
|
+
u = User.create(:name => 'Bob', :other => :bar, :status => :inactive, :so => :mac, :gui => :gtk, :language => :en, :sex => false, :cool => false)
|
54
54
|
expect(u.errors.messages).to be_blank
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
58
|
-
u = User.create(:name => 'Niu'
|
57
|
+
it 'should work nice with default values from active model' do
|
58
|
+
u = User.create(:name => 'Niu', :other => :bar, :so => :mac, :gui => :gtk, :language => :en, :sex => false, :cool => false)
|
59
59
|
expect(u.errors.messages).to be_blank
|
60
60
|
expect(u.status).to eql(:active)
|
61
61
|
expect(u).to be_active
|
62
62
|
end
|
63
63
|
|
64
|
-
describe
|
65
|
-
it
|
64
|
+
describe '.symbolized_attributes' do
|
65
|
+
it 'returns the symbolized attribute for the class' do
|
66
66
|
expect(UserExtra.symbolized_attributes).to eq ['key']
|
67
|
-
expect(Permission.symbolized_attributes).to match_array
|
68
|
-
expect(PermissionSubclass.symbolized_attributes).to match_array
|
67
|
+
expect(Permission.symbolized_attributes).to match_array %w(kind lvl)
|
68
|
+
expect(PermissionSubclass.symbolized_attributes).to match_array %w(kind lvl sub_lvl)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe
|
73
|
-
subject
|
72
|
+
describe 'User Instantiated' do
|
73
|
+
subject do
|
74
74
|
User.create(:name => 'Anna', :other => :fo, :status => status, :so => so, :gui => :qt, :language => :pt, :sex => true, :cool => true)
|
75
|
-
|
75
|
+
end
|
76
76
|
let(:status) { :active }
|
77
77
|
let(:so) { :linux }
|
78
78
|
|
79
|
-
describe
|
79
|
+
describe 'test_symbolize_string' do
|
80
80
|
let(:status) { 'inactive' }
|
81
81
|
|
82
82
|
describe '#status' do
|
@@ -87,7 +87,7 @@ describe "Symbolize" do
|
|
87
87
|
# @user.read_attribute(:status).should eql('inactive')
|
88
88
|
end
|
89
89
|
|
90
|
-
describe
|
90
|
+
describe 'test_symbolize_symbol' do
|
91
91
|
describe '#status' do
|
92
92
|
subject { super().status }
|
93
93
|
it { is_expected.to eq(:active) }
|
@@ -100,7 +100,7 @@ describe "Symbolize" do
|
|
100
100
|
# @user.read_attribute(:status).should eql('active')
|
101
101
|
end
|
102
102
|
|
103
|
-
describe
|
103
|
+
describe 'should work nice with numbers' do
|
104
104
|
let(:status) { 43 }
|
105
105
|
|
106
106
|
describe '#status' do
|
@@ -111,7 +111,7 @@ describe "Symbolize" do
|
|
111
111
|
# @user.read_attribute(:status).should be_nil
|
112
112
|
end
|
113
113
|
|
114
|
-
describe
|
114
|
+
describe 'should acts nice with nil' do
|
115
115
|
let(:status) { nil }
|
116
116
|
|
117
117
|
describe '#status' do
|
@@ -126,8 +126,8 @@ describe "Symbolize" do
|
|
126
126
|
it { expect(subject.read_attribute(:status)).to be_nil }
|
127
127
|
end
|
128
128
|
|
129
|
-
describe
|
130
|
-
let(:status) {
|
129
|
+
describe 'should acts nice with blank' do
|
130
|
+
let(:status) { '' }
|
131
131
|
|
132
132
|
describe '#status' do
|
133
133
|
subject { super().status }
|
@@ -141,69 +141,69 @@ describe "Symbolize" do
|
|
141
141
|
it { expect(subject.read_attribute(:status)).to be_nil }
|
142
142
|
end
|
143
143
|
|
144
|
-
it
|
144
|
+
it 'should not validates other' do
|
145
145
|
subject.other = nil
|
146
146
|
expect(subject).to be_valid
|
147
|
-
subject.other =
|
147
|
+
subject.other = ''
|
148
148
|
expect(subject).to be_valid
|
149
149
|
end
|
150
150
|
|
151
|
-
it
|
152
|
-
expect(User.get_status_values).to eql([[
|
153
|
-
expect(User::STATUS_VALUES).to eql(
|
151
|
+
it 'should get the correct values' do
|
152
|
+
expect(User.get_status_values).to eql([['Active', :active], ['Inactive', :inactive]])
|
153
|
+
expect(User::STATUS_VALUES).to eql(:inactive => 'Inactive', :active => 'Active')
|
154
154
|
end
|
155
155
|
|
156
|
-
it
|
157
|
-
expect(User.status_enum).to eql([[
|
156
|
+
it 'should get the values for RailsAdmin' do
|
157
|
+
expect(User.status_enum).to eql([['Active', :active], ['Inactive', :inactive]])
|
158
158
|
end
|
159
159
|
|
160
|
-
describe
|
160
|
+
describe 'test_symbolize_humanize' do
|
161
161
|
describe '#status_text' do
|
162
162
|
subject { super().status_text }
|
163
|
-
it { is_expected.to eql(
|
163
|
+
it { is_expected.to eql('Active') }
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
167
|
-
it
|
168
|
-
expect(User.get_gui_values).to match_array([[
|
169
|
-
expect(User::GUI_VALUES).to eql(
|
167
|
+
it 'should get the correct values' do
|
168
|
+
expect(User.get_gui_values).to match_array([['cocoa', :cocoa], ['qt', :qt], ['gtk', :gtk]])
|
169
|
+
expect(User::GUI_VALUES).to eql(:cocoa => 'cocoa', :qt => 'qt', :gtk => 'gtk')
|
170
170
|
end
|
171
171
|
|
172
|
-
describe
|
172
|
+
describe 'test_symbolize_humanize' do
|
173
173
|
describe '#gui_text' do
|
174
174
|
subject { super().gui_text }
|
175
|
-
it { is_expected.to eql(
|
175
|
+
it { is_expected.to eql('qt') }
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
-
it
|
180
|
-
expect(User.get_so_values).to match_array([[
|
181
|
-
expect(User::SO_VALUES).to eql(
|
179
|
+
it 'should get the correct values' do
|
180
|
+
expect(User.get_so_values).to match_array([['Linux', :linux], ['Mac OS X', :mac], ['Videogame', :win]])
|
181
|
+
expect(User::SO_VALUES).to eql(:linux => 'Linux', :mac => 'Mac OS X', :win => 'Videogame')
|
182
182
|
end
|
183
183
|
|
184
|
-
describe
|
184
|
+
describe 'test_symbolize_humanize' do
|
185
185
|
describe '#so_text' do
|
186
186
|
subject { super().so_text }
|
187
|
-
it { is_expected.to eql(
|
187
|
+
it { is_expected.to eql('Linux') }
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
-
describe
|
191
|
+
describe 'test_symbolize_humanize' do
|
192
192
|
let(:so) { :mac }
|
193
193
|
|
194
194
|
describe '#so_text' do
|
195
195
|
subject { super().so_text }
|
196
|
-
it { is_expected.to eql(
|
196
|
+
it { is_expected.to eql('Mac OS X') }
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
-
it
|
201
|
-
expect(subject.other_text).to eql(
|
200
|
+
it 'should stringify' do
|
201
|
+
expect(subject.other_text).to eql('fo')
|
202
202
|
subject.other = :foo
|
203
|
-
expect(subject.other_text).to eql(
|
203
|
+
expect(subject.other_text).to eql('foo')
|
204
204
|
end
|
205
205
|
|
206
|
-
describe
|
206
|
+
describe 'should validate status' do
|
207
207
|
let(:status) { nil }
|
208
208
|
it { is_expected.not_to be_valid }
|
209
209
|
it 'has 1 error' do
|
@@ -211,62 +211,62 @@ describe "Symbolize" do
|
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
|
-
it
|
214
|
+
it 'should not validate so' do
|
215
215
|
subject.so = nil
|
216
216
|
expect(subject).to be_valid
|
217
217
|
end
|
218
218
|
|
219
|
-
it
|
219
|
+
it 'test_symbols_with_weird_chars_quoted_id' do
|
220
220
|
subject.status = :"weird'; chars"
|
221
221
|
expect(subject.status_before_type_cast).to eql(:"weird'; chars")
|
222
222
|
end
|
223
223
|
|
224
|
-
it
|
224
|
+
it 'should work fine through relations' do
|
225
225
|
subject.extras.create(:key => :one)
|
226
226
|
expect(UserExtra.first.key).to eql(:one)
|
227
227
|
end
|
228
228
|
|
229
|
-
it
|
229
|
+
it 'should play fine with null db columns' do
|
230
230
|
new_extra = subject.extras.build
|
231
231
|
expect(new_extra).not_to be_valid
|
232
232
|
end
|
233
233
|
|
234
|
-
it
|
234
|
+
it 'should play fine with null db columns' do
|
235
235
|
new_extra = subject.extras.build
|
236
236
|
expect(new_extra).not_to be_valid
|
237
237
|
end
|
238
238
|
|
239
|
-
describe
|
239
|
+
describe 'i18n' do
|
240
240
|
|
241
|
-
it
|
242
|
-
expect(subject.language_text).to eql(
|
241
|
+
it 'should test i18n ones' do
|
242
|
+
expect(subject.language_text).to eql('Português')
|
243
243
|
end
|
244
244
|
|
245
|
-
it
|
246
|
-
expect(User.get_language_values).to match_array([[
|
245
|
+
it 'should get the correct values' do
|
246
|
+
expect(User.get_language_values).to match_array([['Português', :pt], ['Inglês', :en]])
|
247
247
|
end
|
248
248
|
|
249
|
-
it
|
250
|
-
expect(User::LANGUAGE_VALUES).to eql(
|
249
|
+
it 'should get the correct values' do
|
250
|
+
expect(User::LANGUAGE_VALUES).to eql(:pt => 'pt', :en => 'en')
|
251
251
|
end
|
252
252
|
|
253
|
-
it
|
254
|
-
expect(subject.sex_text).to eql(
|
253
|
+
it 'should test boolean' do
|
254
|
+
expect(subject.sex_text).to eql('Feminino')
|
255
255
|
subject.sex = false
|
256
256
|
expect(subject.sex_text).to eql('Masculino')
|
257
257
|
end
|
258
258
|
|
259
|
-
it
|
260
|
-
expect(User.get_sex_values).to eql([[
|
259
|
+
it 'should get the correct values' do
|
260
|
+
expect(User.get_sex_values).to eql([['Feminino', true], ['Masculino', false]])
|
261
261
|
end
|
262
262
|
|
263
|
-
it
|
264
|
-
expect(User::SEX_VALUES).to eql(
|
263
|
+
it 'should get the correct values' do
|
264
|
+
expect(User::SEX_VALUES).to eql(true => 'true', false => 'false')
|
265
265
|
end
|
266
266
|
|
267
|
-
it
|
267
|
+
it 'should translate a multiword class' do
|
268
268
|
@skill = UserSkill.create(:kind => :magic)
|
269
|
-
expect(@skill.kind_text).to eql(
|
269
|
+
expect(@skill.kind_text).to eql('Mágica')
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should return nil if there's no value" do
|
@@ -276,30 +276,30 @@ describe "Symbolize" do
|
|
276
276
|
|
277
277
|
end
|
278
278
|
|
279
|
-
describe
|
279
|
+
describe 'Methods' do
|
280
280
|
|
281
|
-
it
|
281
|
+
it 'should play nice with other stuff' do
|
282
282
|
expect(subject.karma).to be_nil
|
283
|
-
expect(User::KARMA_VALUES).to eql(
|
283
|
+
expect(User::KARMA_VALUES).to eql(:bad => 'bad', :ugly => 'ugly', :good => 'good')
|
284
284
|
end
|
285
285
|
|
286
|
-
it
|
286
|
+
it 'should provide a boolean method' do
|
287
287
|
expect(subject).not_to be_good
|
288
288
|
subject.karma = :ugly
|
289
289
|
expect(subject).to be_ugly
|
290
290
|
end
|
291
291
|
|
292
|
-
it
|
293
|
-
subject.karma =
|
292
|
+
it 'should work' do
|
293
|
+
subject.karma = 'good'
|
294
294
|
expect(subject).to be_good
|
295
295
|
expect(subject).not_to be_bad
|
296
296
|
end
|
297
297
|
|
298
298
|
end
|
299
299
|
|
300
|
-
describe
|
300
|
+
describe 'Changes' do
|
301
301
|
|
302
|
-
it
|
302
|
+
it 'is dirty if you change the attribute value' do
|
303
303
|
expect(subject.language).to eq(:pt)
|
304
304
|
expect(subject.language_changed?).to be false
|
305
305
|
|
@@ -308,7 +308,7 @@ describe "Symbolize" do
|
|
308
308
|
expect(subject.language_changed?).to be true
|
309
309
|
end
|
310
310
|
|
311
|
-
it
|
311
|
+
it 'is not dirty if you set the attribute value to the same value' do
|
312
312
|
expect(subject.language).to eq(:pt)
|
313
313
|
expect(subject.language_changed?).to be false
|
314
314
|
|
@@ -317,15 +317,15 @@ describe "Symbolize" do
|
|
317
317
|
expect(subject.language_changed?).to be false
|
318
318
|
end
|
319
319
|
|
320
|
-
it
|
320
|
+
it 'is not dirty if you set the attribute value to the same value (string)' do
|
321
321
|
expect(subject.language).to eq(:pt)
|
322
322
|
expect(subject.language_changed?).to be false
|
323
323
|
|
324
|
-
|
324
|
+
subject.language = 'pt'
|
325
325
|
expect(subject.language_changed?).to be false
|
326
326
|
end
|
327
327
|
|
328
|
-
it
|
328
|
+
it 'is not dirty if you set the default attribute value to the same value' do
|
329
329
|
user = User.create!(:language => :pt, :sex => true, :cool => true)
|
330
330
|
expect(user.status).to eq(:active)
|
331
331
|
expect(user).not_to be_changed
|
@@ -334,7 +334,7 @@ describe "Symbolize" do
|
|
334
334
|
expect(user).not_to be_changed
|
335
335
|
end
|
336
336
|
|
337
|
-
it
|
337
|
+
it 'is not dirty if you set the default attribute value to the same value (string)' do
|
338
338
|
user = User.create!(:language => :pt, :sex => true, :cool => true)
|
339
339
|
expect(user.status).to eq(:active)
|
340
340
|
expect(user).not_to be_changed
|
@@ -346,67 +346,67 @@ describe "Symbolize" do
|
|
346
346
|
|
347
347
|
end
|
348
348
|
|
349
|
-
describe
|
349
|
+
describe 'more tests on Permission' do
|
350
350
|
|
351
|
-
it
|
351
|
+
it 'should use default value on object build' do
|
352
352
|
expect(Permission.new.kind).to eql(:perm)
|
353
353
|
end
|
354
354
|
|
355
|
-
it
|
356
|
-
Permission.create!(:name =>
|
357
|
-
expect(Permission.find_by_name(
|
355
|
+
it 'should not interfer on create' do
|
356
|
+
Permission.create!(:name => 'p7', :kind => :temp, :lvl => 7)
|
357
|
+
expect(Permission.find_by_name('p7').kind).to eql(:temp)
|
358
358
|
end
|
359
359
|
|
360
|
-
it
|
361
|
-
pm = Permission.new(:name =>
|
360
|
+
it 'should work on create' do
|
361
|
+
pm = Permission.new(:name => 'p7', :lvl => 7)
|
362
362
|
expect(pm).to be_valid
|
363
363
|
expect(pm.save).to be true
|
364
364
|
end
|
365
365
|
|
366
|
-
it
|
367
|
-
Permission.create!(:name =>
|
368
|
-
expect(Permission.find_by_name(
|
366
|
+
it 'should work on create' do
|
367
|
+
Permission.create!(:name => 'p8', :lvl => 9)
|
368
|
+
expect(Permission.find_by_name('p8').kind).to eql(:perm)
|
369
369
|
end
|
370
370
|
|
371
|
-
it
|
372
|
-
Permission.create!(:name =>
|
373
|
-
pm = Permission.find_by_name(
|
371
|
+
it 'should work on edit' do
|
372
|
+
Permission.create!(:name => 'p8', :lvl => 9)
|
373
|
+
pm = Permission.find_by_name('p8')
|
374
374
|
pm.kind = :temp
|
375
375
|
pm.save
|
376
|
-
expect(Permission.find_by_name(
|
376
|
+
expect(Permission.find_by_name('p8').kind).to eql(:temp)
|
377
377
|
end
|
378
378
|
|
379
|
-
it
|
380
|
-
pm = Permission.new(:name =>
|
379
|
+
it 'should work with default values' do
|
380
|
+
pm = Permission.new(:name => 'p9')
|
381
381
|
pm.lvl = 9
|
382
382
|
pm.save
|
383
|
-
expect(Permission.find_by_name(
|
383
|
+
expect(Permission.find_by_name('p9').lvl.to_i).to eql(9)
|
384
384
|
end
|
385
385
|
|
386
386
|
end
|
387
387
|
|
388
|
-
describe
|
388
|
+
describe 'Named Scopes' do
|
389
389
|
|
390
390
|
before do
|
391
|
-
@anna = User.create(:name => 'Anna', :other => :fo, :status => :active
|
391
|
+
@anna = User.create(:name => 'Anna', :other => :fo, :status => :active, :so => :linux, :gui => :qt, :language => :pt, :sex => true, :cool => true)
|
392
392
|
@mary = User.create(:name => 'Mary', :other => :fo, :status => :inactive, :so => :mac, :language => :pt, :sex => true, :cool => true)
|
393
393
|
end
|
394
394
|
|
395
|
-
it
|
396
|
-
expect(User.where(
|
395
|
+
it 'test_symbolized_finder' do
|
396
|
+
expect(User.where(:status => :inactive).all.map(&:name)).to eql(['Mary'])
|
397
397
|
end
|
398
398
|
|
399
|
-
it
|
400
|
-
User.where(
|
399
|
+
it 'test_symbolized_scoping' do
|
400
|
+
User.where(:status => :inactive).scoping do
|
401
401
|
expect(User.all.map(&:name)).to eql(['Mary'])
|
402
402
|
end
|
403
403
|
end
|
404
404
|
|
405
|
-
it
|
405
|
+
it 'should have main named scope' do
|
406
406
|
expect(User.inactive).to eq([@mary])
|
407
407
|
end
|
408
408
|
|
409
|
-
it
|
409
|
+
it 'should have other to test better' do
|
410
410
|
expect(User.so(:linux)).to eq([@anna])
|
411
411
|
end
|
412
412
|
|
@@ -428,25 +428,24 @@ describe "Symbolize" do
|
|
428
428
|
|
429
429
|
end
|
430
430
|
|
431
|
-
|
432
|
-
describe ": Default Value" do
|
431
|
+
describe ': Default Value' do
|
433
432
|
before(:each) do
|
434
|
-
@user = User.new(:name => 'Anna', :other => :fo, :status => :active
|
433
|
+
@user = User.new(:name => 'Anna', :other => :fo, :status => :active, :so => :linux, :gui => :qt, :language => :pt, :sex => true, :cool => true)
|
435
434
|
end
|
436
435
|
|
437
|
-
it
|
436
|
+
it 'should be considered during validation' do
|
438
437
|
@user.valid?
|
439
438
|
expect(@user.errors.full_messages).to eq([])
|
440
439
|
end
|
441
440
|
|
442
|
-
it
|
441
|
+
it 'should be taken from the DB schema definition' do
|
443
442
|
expect(@user.country).to eq(:pt)
|
444
|
-
expect(@user.country_text).to eq(
|
443
|
+
expect(@user.country_text).to eq('Pt')
|
445
444
|
end
|
446
445
|
|
447
|
-
it
|
446
|
+
it 'should be applied to new, just saved, and reloaded objects, and also play fine with :methods option' do
|
448
447
|
expect(@user.role).to eq(:reader)
|
449
|
-
expect(@user.role_text).to eq(
|
448
|
+
expect(@user.role_text).to eq('reader')
|
450
449
|
expect(@user).to be_reader
|
451
450
|
@user.save!
|
452
451
|
expect(@user.role).to eq(:reader)
|
@@ -456,7 +455,7 @@ describe "Symbolize" do
|
|
456
455
|
expect(@user).to be_reader
|
457
456
|
end
|
458
457
|
|
459
|
-
it
|
458
|
+
it 'should be overridable' do
|
460
459
|
@user.role = :writer
|
461
460
|
expect(@user.role).to eq(:writer)
|
462
461
|
expect(@user).to be_writer
|
@@ -471,12 +470,12 @@ describe "Symbolize" do
|
|
471
470
|
# This feature is for the next major version (b/o the compatibility problem)
|
472
471
|
it "should detect name collision caused by ':methods => true' option" do
|
473
472
|
pending 'next major version'
|
474
|
-
expect
|
473
|
+
expect do
|
475
474
|
User.class_eval do
|
476
475
|
# 'reader?' method is already defined, so the line below should raise an error
|
477
476
|
symbolize :some_attr, :in => [:reader, :guest], :methods => true
|
478
477
|
end
|
479
|
-
|
478
|
+
end.to raise_error(ArgumentError)
|
480
479
|
end
|
481
480
|
|
482
481
|
end
|