symbolize 4.0.3 → 4.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +24 -0
- data/lib/symbolize/active_record.rb +7 -12
- data/lib/symbolize/version.rb +1 -1
- data/spec/db/001_create_testing_structure.rb +2 -1
- data/spec/locales/pt.yml +3 -0
- data/spec/spec_helper_ar.rb +11 -1
- data/spec/spec_helper_mongoid.rb +10 -2
- data/spec/support/ar_models.rb +41 -0
- data/spec/support/mongoid_models.rb +64 -0
- data/spec/symbolize/active_record_spec.rb +68 -156
- data/spec/symbolize/mongoid_spec.rb +15 -55
- metadata +22 -12
data/Rakefile
CHANGED
@@ -1,6 +1,30 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
#require "rake"
|
5
|
+
# require "rdoc/task"
|
1
6
|
require "rspec"
|
2
7
|
require "rspec/core/rake_task"
|
3
8
|
|
9
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
10
|
+
require "symbolize/version"
|
11
|
+
|
12
|
+
task :gem => :build
|
13
|
+
task :build do
|
14
|
+
system "gem build symbolize.gemspec"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :install => :build do
|
18
|
+
system "sudo gem install symbolize-#{Symbolize::VERSION}.gem"
|
19
|
+
end
|
20
|
+
|
21
|
+
task :release => :build do
|
22
|
+
system "git tag -a v#{Symbolize::VERSION} -m 'Tagging #{Symbolize::VERSION}'"
|
23
|
+
system "git push --tags"
|
24
|
+
system "gem push symbolize-#{Symbolize::VERSION}.gem"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
4
28
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
5
29
|
spec.pattern = "spec/**/*_spec.rb"
|
6
30
|
end
|
@@ -91,7 +91,7 @@ module Symbolize
|
|
91
91
|
values.each do |value|
|
92
92
|
key = value[0]
|
93
93
|
define_method("#{key}?") do
|
94
|
-
self[attr_name] == key
|
94
|
+
self[attr_name].to_s == key.to_s
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
@@ -99,16 +99,11 @@ module Symbolize
|
|
99
99
|
if scopes
|
100
100
|
scope_comm = lambda { |*args| ActiveRecord::VERSION::MAJOR >= 3 ? scope(*args) : named_scope(*args)}
|
101
101
|
values.each do |value|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
if
|
106
|
-
|
107
|
-
scope_comm.call "without_#{attr_name}".to_sym, :conditions => { attr_name => '0' }
|
108
|
-
|
109
|
-
scope_comm.call attr_name.to_sym, :conditions => { attr_name => '1' }
|
110
|
-
scope_comm.call "not_#{attr_name}".to_sym, :conditions => { attr_name => '0' }
|
111
|
-
end
|
102
|
+
name = value[0]
|
103
|
+
if name.respond_to?(:to_sym)
|
104
|
+
scope_comm.call name.to_sym, :conditions => { attr_name => name }
|
105
|
+
# Figure out if this as another option, or default...
|
106
|
+
# scope_comm.call "not_#{attr_name}".to_sym, :conditions => { attr_name != name }
|
112
107
|
end
|
113
108
|
end
|
114
109
|
end
|
@@ -171,7 +166,7 @@ module Symbolize
|
|
171
166
|
val = { "true" => true, "false" => false }[value]
|
172
167
|
val = symbolize_attribute(value) if val.nil?
|
173
168
|
|
174
|
-
self[attr_name] = val #.to_s
|
169
|
+
self[attr_name] = val #.to_s
|
175
170
|
end
|
176
171
|
end
|
177
172
|
|
data/lib/symbolize/version.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
class CreateTestingStructure < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :users do |t|
|
4
|
-
t.string :name, :so, :gui, :other, :
|
4
|
+
t.string :name, :so, :gui, :other, :language, :kind
|
5
|
+
t.string :status, :default => :active
|
5
6
|
t.string :limited, :limit => 10
|
6
7
|
t.string :karma, :limit => 5
|
7
8
|
t.boolean :sex
|
data/spec/locales/pt.yml
CHANGED
data/spec/spec_helper_ar.rb
CHANGED
@@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
|
3
3
|
require 'active_record'
|
4
4
|
require 'symbolize/active_record'
|
5
|
-
|
6
5
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") #'postgresql', :database => 'symbolize_test', :username => 'postgres')
|
7
6
|
|
8
7
|
if ActiveRecord::VERSION::STRING >= "3.1"
|
@@ -12,6 +11,17 @@ else
|
|
12
11
|
CreateTestingStructure.migrate(:up)
|
13
12
|
end
|
14
13
|
|
14
|
+
require 'support/ar_models'
|
15
|
+
|
15
16
|
puts "Running AR #{ActiveRecord::VERSION::STRING}"
|
16
17
|
# Spec::Runner.configure do |config|
|
17
18
|
# end
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
|
22
|
+
config.after(:each) do
|
23
|
+
[User, Permission].each { |klass| klass.delete_all }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
data/spec/spec_helper_mongoid.rb
CHANGED
@@ -2,8 +2,16 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
require 'mongoid'
|
3
3
|
|
4
4
|
Mongoid.configure do |config|
|
5
|
-
config.master = Mongo::Connection.new.db("
|
5
|
+
config.master = Mongo::Connection.new.db("symbolize_test")
|
6
6
|
end
|
7
7
|
|
8
|
-
|
8
|
+
Mongoid.database.collections.each do |collection|
|
9
|
+
unless collection.name =~ /^system\./
|
10
|
+
collection.remove
|
11
|
+
end
|
12
|
+
end
|
9
13
|
|
14
|
+
puts "Running Mongoid 2"
|
15
|
+
|
16
|
+
require 'symbolize/mongoid'
|
17
|
+
require 'support/mongoid_models'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Test model
|
4
|
+
class User < ActiveRecord::Base
|
5
|
+
symbolize :other
|
6
|
+
symbolize :language, :in => [:pt, :en]
|
7
|
+
symbolize :sex, :in => [true, false], :scopes => true
|
8
|
+
symbolize :status , :in => [:active, :inactive], :i18n => false, :capitalize => true, :scopes => true, :methods => true
|
9
|
+
symbolize :so, :allow_blank => true, :in => {
|
10
|
+
:linux => 'Linux',
|
11
|
+
:mac => 'Mac OS X',
|
12
|
+
:win => 'Videogame'
|
13
|
+
}, :scopes => true
|
14
|
+
symbolize :gui, :allow_blank => true, :in => [:cocoa, :qt, :gtk], :i18n => false
|
15
|
+
symbolize :karma, :in => %w{ good bad ugly}, :methods => true, :i18n => false, :allow_nil => true
|
16
|
+
symbolize :cool, :in => [true, false], :scopes => true
|
17
|
+
|
18
|
+
has_many :extras, :dependent => :destroy, :class_name => "UserExtra"
|
19
|
+
has_many :access, :dependent => :destroy, :class_name => "UserAccess"
|
20
|
+
end
|
21
|
+
|
22
|
+
class UserSkill < ActiveRecord::Base
|
23
|
+
symbolize :kind, :in => [:agility, :magic]
|
24
|
+
end
|
25
|
+
|
26
|
+
class UserExtra < ActiveRecord::Base
|
27
|
+
symbolize :key, :in => [:one, :another]
|
28
|
+
end
|
29
|
+
|
30
|
+
class Permission < ActiveRecord::Base
|
31
|
+
validates_presence_of :name
|
32
|
+
symbolize :kind, :in => [:temp, :perm], :default => :perm
|
33
|
+
symbolize :lvl, :in => (1..9).to_a, :i18n => false#, :default => 1
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make with_scope public-usable for testing
|
37
|
+
#if ActiveRecord::VERSION::MAJOR < 3
|
38
|
+
class << ActiveRecord::Base
|
39
|
+
public :with_scope
|
40
|
+
end
|
41
|
+
#end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Test model
|
4
|
+
class Person
|
5
|
+
include Mongoid::Document
|
6
|
+
include Mongoid::Symbolize
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
|
9
|
+
symbolize :other
|
10
|
+
symbolize :language, :in => [:pt, :en]
|
11
|
+
# symbolize :sex, :in => [true, false], :scopes => true
|
12
|
+
symbolize :status , :in => [:active, :inactive], :i18n => false, :capitalize => true, :scopes => true
|
13
|
+
symbolize :so, :allow_blank => true, :in => {
|
14
|
+
:linux => 'Linux',
|
15
|
+
:mac => 'Mac OS X',
|
16
|
+
:win => 'Videogame'
|
17
|
+
}, :scopes => true
|
18
|
+
symbolize :gui, :allow_blank => true, :in => [:cocoa, :qt, :gtk], :i18n => false
|
19
|
+
symbolize :karma, :in => %w{good bad ugly}, :methods => true, :i18n => false, :allow_nil => true
|
20
|
+
symbolize :planet, :in => %w{earth centauri tatooine}, :default => :earth
|
21
|
+
# symbolize :cool, :in => [true, false], :scopes => true
|
22
|
+
|
23
|
+
has_many :rights, :dependent => :destroy
|
24
|
+
has_many :extras, :dependent => :destroy, :class_name => "PersonExtra"
|
25
|
+
embeds_many :skills, :class_name => "PersonSkill"
|
26
|
+
end
|
27
|
+
|
28
|
+
class PersonSkill
|
29
|
+
include Mongoid::Document
|
30
|
+
include Mongoid::Symbolize
|
31
|
+
embedded_in :person, :inverse_of => :skills
|
32
|
+
|
33
|
+
symbolize :kind, :in => [:agility, :magic]
|
34
|
+
end
|
35
|
+
|
36
|
+
class PersonExtra
|
37
|
+
include Mongoid::Document
|
38
|
+
include Mongoid::Symbolize
|
39
|
+
belongs_to :person, :inverse_of => :extras
|
40
|
+
|
41
|
+
symbolize :key, :in => [:one, :another]
|
42
|
+
end
|
43
|
+
|
44
|
+
class Right
|
45
|
+
include Mongoid::Document
|
46
|
+
include Mongoid::Symbolize
|
47
|
+
|
48
|
+
validates_presence_of :name
|
49
|
+
symbolize :kind, :in => [:temp, :perm], :default => :perm
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
class Project
|
54
|
+
include Mongoid::Document
|
55
|
+
|
56
|
+
field :name
|
57
|
+
field :state, :default => 'active'
|
58
|
+
|
59
|
+
# Comment 1 line and it works, both fails:
|
60
|
+
default_scope where(:state => 'active')
|
61
|
+
# scope :inactive, any_in(:state => [:done, :wip])
|
62
|
+
scope :dead, all_of(:state => :wip, :name => "zim")
|
63
|
+
|
64
|
+
end
|
@@ -1,61 +1,28 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require File.dirname(__FILE__) + '/../spec_helper_ar'
|
3
3
|
|
4
|
-
#
|
5
|
-
# Test model
|
6
|
-
class User < ActiveRecord::Base
|
7
|
-
symbolize :other
|
8
|
-
symbolize :language, :in => [:pt, :en]
|
9
|
-
symbolize :sex, :in => [true, false], :scopes => true
|
10
|
-
symbolize :status , :in => [:active, :inactive], :i18n => false, :capitalize => true, :scopes => true
|
11
|
-
symbolize :so, :allow_blank => true, :in => {
|
12
|
-
:linux => 'Linux',
|
13
|
-
:mac => 'Mac OS X',
|
14
|
-
:win => 'Videogame'
|
15
|
-
}, :scopes => true
|
16
|
-
symbolize :gui, :allow_blank => true, :in => [:cocoa, :qt, :gtk], :i18n => false
|
17
|
-
symbolize :karma, :in => %w{ good bad ugly}, :methods => true, :i18n => false, :allow_nil => true
|
18
|
-
symbolize :cool, :in => [true, false], :scopes => true
|
19
|
-
|
20
|
-
has_many :extras, :dependent => :destroy, :class_name => "UserExtra"
|
21
|
-
has_many :access, :dependent => :destroy, :class_name => "UserAccess"
|
22
|
-
end
|
23
|
-
|
24
|
-
class UserSkill < ActiveRecord::Base
|
25
|
-
symbolize :kind, :in => [:agility, :magic]
|
26
|
-
end
|
27
|
-
|
28
|
-
class UserExtra < ActiveRecord::Base
|
29
|
-
symbolize :key, :in => [:one, :another]
|
30
|
-
end
|
31
|
-
|
32
|
-
class Permission < ActiveRecord::Base
|
33
|
-
validates_presence_of :name
|
34
|
-
symbolize :kind, :in => [:temp, :perm], :default => :perm
|
35
|
-
symbolize :lvl, :in => (1..9).to_a, :i18n => false#, :default => 1
|
36
|
-
end
|
37
|
-
|
38
|
-
# Make with_scope public-usable for testing
|
39
|
-
#if ActiveRecord::VERSION::MAJOR < 3
|
40
|
-
class << ActiveRecord::Base
|
41
|
-
public :with_scope
|
42
|
-
end
|
43
|
-
#end
|
44
|
-
|
45
|
-
# Test records
|
46
|
-
User.create(:name => 'Anna', :other => :fo, :status => :active , :so => :linux, :gui => :qt, :language => :pt, :sex => true, :cool => true)
|
47
|
-
User.create!(:name => 'Bob' , :other => :bar,:status => :inactive, :so => :mac, :gui => :gtk, :language => :en, :sex => false, :cool => false)
|
48
|
-
|
49
|
-
|
50
4
|
describe "Symbolize" do
|
51
5
|
|
52
6
|
it "should respond to symbolize" do
|
53
7
|
ActiveRecord::Base.should respond_to :symbolize
|
54
8
|
end
|
55
9
|
|
10
|
+
it "should have a valid blueprint" do
|
11
|
+
# Test records
|
12
|
+
u = User.create(:name => 'Bob' , :other => :bar,:status => :inactive, :so => :mac, :gui => :gtk, :language => :en, :sex => false, :cool => false)
|
13
|
+
u.errors.messages.should eql({})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should work nice with default values from active model" do
|
17
|
+
u = User.create(:name => 'Niu' , :other => :bar, :so => :mac, :gui => :gtk, :language => :en, :sex => false, :cool => false)
|
18
|
+
u.errors.messages.should eql({})
|
19
|
+
u.status.should eql(:active)
|
20
|
+
u.should be_active
|
21
|
+
end
|
22
|
+
|
56
23
|
describe "User Instantiated" do
|
57
24
|
before(:each) do
|
58
|
-
@user = User.
|
25
|
+
@user = User.create(:name => 'Anna', :other => :fo, :status => :active , :so => :linux, :gui => :qt, :language => :pt, :sex => true, :cool => true)
|
59
26
|
end
|
60
27
|
|
61
28
|
it "test_symbolize_string" do
|
@@ -238,6 +205,28 @@ describe "Symbolize" do
|
|
238
205
|
|
239
206
|
end
|
240
207
|
|
208
|
+
describe "Methods" do
|
209
|
+
|
210
|
+
it "is dirty if you change the attribute value" do
|
211
|
+
@user.language.should == :pt
|
212
|
+
@user.language_changed?.should be_false
|
213
|
+
|
214
|
+
return_value = @user.language = :en
|
215
|
+
return_value.should == :en
|
216
|
+
@user.language_changed?.should be_true
|
217
|
+
end
|
218
|
+
|
219
|
+
it "is not dirty if you set the attribute value to the same value" do
|
220
|
+
@user.language.should == :pt
|
221
|
+
@user.language_changed?.should be_false
|
222
|
+
|
223
|
+
return_value = @user.language = :pt
|
224
|
+
return_value.should == :pt
|
225
|
+
@user.language_changed?.should be_false
|
226
|
+
end
|
227
|
+
|
228
|
+
end
|
229
|
+
|
241
230
|
end
|
242
231
|
|
243
232
|
describe "more tests on Permission" do
|
@@ -263,6 +252,7 @@ describe "Symbolize" do
|
|
263
252
|
end
|
264
253
|
|
265
254
|
it "should work on edit" do
|
255
|
+
Permission.create!(:name => "p8", :lvl => 9)
|
266
256
|
pm = Permission.find_by_name("p8")
|
267
257
|
pm.kind = :temp
|
268
258
|
pm.save
|
@@ -278,125 +268,47 @@ describe "Symbolize" do
|
|
278
268
|
|
279
269
|
end
|
280
270
|
|
281
|
-
describe "
|
282
|
-
|
283
|
-
#
|
284
|
-
# ActiveRecord <= 2
|
285
|
-
#
|
286
|
-
if ActiveRecord::VERSION::MAJOR <= 2
|
287
|
-
|
288
|
-
it "test_symbolized_finder" do
|
289
|
-
User.find(:all, :conditions => { :status => :inactive }).map(&:name).should eql(['Bob'])
|
290
|
-
User.find_all_by_status(:inactive).map(&:name).should eql(['Bob'])
|
291
|
-
end
|
271
|
+
describe "Named Scopes" do
|
292
272
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
end
|
298
|
-
|
299
|
-
describe "dirty tracking / changed flag" do
|
300
|
-
before do
|
301
|
-
@anna = User.find_by_name!('Anna')
|
302
|
-
end
|
303
|
-
|
304
|
-
it "is dirty if you change the attribute value" do
|
305
|
-
@anna.language.should == :pt
|
306
|
-
@anna.language_changed?.should be_false
|
307
|
-
|
308
|
-
return_value = @anna.language = :en
|
309
|
-
return_value.should == :en
|
310
|
-
@anna.language_changed?.should be_true
|
311
|
-
end
|
312
|
-
|
313
|
-
it "is not dirty if you set the attribute value to the same value it was originally" do
|
314
|
-
@anna.language.should == :pt
|
315
|
-
@anna.language_changed?.should be_false
|
316
|
-
|
317
|
-
return_value = @anna.language = :pt
|
318
|
-
return_value.should == :pt
|
319
|
-
@anna.language_changed?.should be_false
|
320
|
-
end
|
321
|
-
end
|
322
|
-
|
323
|
-
#
|
324
|
-
# ActiveRecord >= 3
|
325
|
-
#
|
326
|
-
else
|
327
|
-
|
328
|
-
it "test_symbolized_finder" do
|
329
|
-
User.where({ :status => :inactive }).all.map(&:name).should eql(['Bob'])
|
330
|
-
User.find_all_by_status(:inactive).map(&:name).should eql(['Bob'])
|
331
|
-
end
|
332
|
-
|
333
|
-
it "test_symbolized_with_scope" do
|
334
|
-
User.with_scope(:find => { :conditions => { :status => :inactive }}) do
|
335
|
-
User.find(:all).map(&:name).should eql(['Bob'])
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
describe "dirty tracking / changed flag" do
|
340
|
-
before do
|
341
|
-
@anna = User.find_by_name!('Anna')
|
342
|
-
end
|
343
|
-
|
344
|
-
it "is dirty if you change the attribute value" do
|
345
|
-
@anna.language.should == :pt
|
346
|
-
@anna.language_changed?.should be_false
|
347
|
-
|
348
|
-
return_value = @anna.language = :en
|
349
|
-
return_value.should == :en
|
350
|
-
@anna.language_changed?.should be_true
|
351
|
-
end
|
273
|
+
before do
|
274
|
+
@anna = User.create(:name => 'Anna', :other => :fo, :status => :active , :so => :linux, :gui => :qt, :language => :pt, :sex => true, :cool => true)
|
275
|
+
@mary = User.create(:name => 'Mary', :other => :fo, :status => :inactive, :so => :mac, :language => :pt, :sex => true, :cool => true)
|
276
|
+
end
|
352
277
|
|
353
|
-
|
354
|
-
|
355
|
-
|
278
|
+
it "test_symbolized_finder" do
|
279
|
+
User.where({ :status => :inactive }).all.map(&:name).should eql(['Mary'])
|
280
|
+
User.find_all_by_status(:inactive).map(&:name).should eql(['Mary'])
|
281
|
+
end
|
356
282
|
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
end
|
283
|
+
it "test_symbolized_with_scope" do
|
284
|
+
User.with_scope(:find => { :conditions => { :status => :inactive }}) do
|
285
|
+
User.all.map(&:name).should eql(['Mary'])
|
361
286
|
end
|
287
|
+
end
|
362
288
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
before do
|
367
|
-
@anna = User.find_by_name!('Anna')
|
368
|
-
@bob = User.find_by_name!('Bob')
|
369
|
-
end
|
370
|
-
|
371
|
-
it "should have main named scope" do
|
372
|
-
User.inactive.should == [@bob]
|
373
|
-
end
|
374
|
-
|
375
|
-
it "should have other to test better" do
|
376
|
-
User.linux.should == [@anna]
|
377
|
-
end
|
378
|
-
|
379
|
-
it "should have 'with' helper" do
|
380
|
-
User.with_sex.should == [@anna]
|
381
|
-
end
|
289
|
+
it "should have main named scope" do
|
290
|
+
User.inactive.should == [@mary]
|
291
|
+
end
|
382
292
|
|
383
|
-
|
384
|
-
|
385
|
-
|
293
|
+
it "should have other to test better" do
|
294
|
+
User.linux.should == [@anna]
|
295
|
+
end
|
386
296
|
|
387
|
-
|
388
|
-
|
389
|
-
|
297
|
+
# it "should have 'with' helper" do
|
298
|
+
# User.with_sex.should == [@anna]
|
299
|
+
# end
|
390
300
|
|
391
|
-
|
392
|
-
|
393
|
-
|
301
|
+
# it "should have 'without' helper" do
|
302
|
+
# User.without_sex.should == [@bob]
|
303
|
+
# end
|
394
304
|
|
395
|
-
|
396
|
-
|
305
|
+
# it "should have 'attr_name' helper" do
|
306
|
+
# User.cool.should == [@anna]
|
307
|
+
# end
|
397
308
|
|
398
|
-
|
309
|
+
# it "should have 'not_attr_name' helper" do
|
310
|
+
# User.not_cool.should == [@bob]
|
311
|
+
# end
|
399
312
|
|
400
313
|
end
|
401
|
-
|
402
314
|
end
|
@@ -1,55 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'spec_helper_mongoid'
|
3
3
|
|
4
|
-
#
|
5
|
-
# Test model
|
6
|
-
class Person
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::Symbolize
|
9
|
-
|
10
|
-
symbolize :other
|
11
|
-
symbolize :language, :in => [:pt, :en]
|
12
|
-
# symbolize :sex, :in => [true, false], :scopes => true
|
13
|
-
symbolize :status , :in => [:active, :inactive], :i18n => false, :capitalize => true, :scopes => true
|
14
|
-
symbolize :so, :allow_blank => true, :in => {
|
15
|
-
:linux => 'Linux',
|
16
|
-
:mac => 'Mac OS X',
|
17
|
-
:win => 'Videogame'
|
18
|
-
}, :scopes => true
|
19
|
-
symbolize :gui, :allow_blank => true, :in => [:cocoa, :qt, :gtk], :i18n => false
|
20
|
-
symbolize :karma, :in => %w{good bad ugly}, :methods => true, :i18n => false, :allow_nil => true
|
21
|
-
symbolize :planet, :in => %w{earth centauri tatooine}, :default => :earth
|
22
|
-
# symbolize :cool, :in => [true, false], :scopes => true
|
23
|
-
|
24
|
-
has_many :rights, :dependent => :destroy
|
25
|
-
has_many :extras, :dependent => :destroy, :class_name => "PersonExtra"
|
26
|
-
embeds_many :skills, :class_name => "PersonSkill"
|
27
|
-
end
|
28
|
-
|
29
|
-
class PersonSkill
|
30
|
-
include Mongoid::Document
|
31
|
-
include Mongoid::Symbolize
|
32
|
-
embedded_in :person, :inverse_of => :skills
|
33
|
-
|
34
|
-
symbolize :kind, :in => [:agility, :magic]
|
35
|
-
end
|
36
|
-
|
37
|
-
class PersonExtra
|
38
|
-
include Mongoid::Document
|
39
|
-
include Mongoid::Symbolize
|
40
|
-
belongs_to :person, :inverse_of => :extras
|
41
|
-
|
42
|
-
symbolize :key, :in => [:one, :another]
|
43
|
-
end
|
44
|
-
|
45
|
-
class Right
|
46
|
-
include Mongoid::Document
|
47
|
-
include Mongoid::Symbolize
|
48
|
-
|
49
|
-
validates_presence_of :name
|
50
|
-
symbolize :kind, :in => [:temp, :perm], :default => :perm
|
51
|
-
end
|
52
|
-
|
53
4
|
describe "Symbolize" do
|
54
5
|
|
55
6
|
it "should be a module" do
|
@@ -279,6 +230,21 @@ describe "Symbolize" do
|
|
279
230
|
|
280
231
|
end
|
281
232
|
|
233
|
+
describe "Scopes" do
|
234
|
+
it "should work under scope" do
|
235
|
+
# Person.with_scope({ :status => :inactive }) do
|
236
|
+
# Person.all.map(&:name).should eql(['Bob'])
|
237
|
+
# end
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should work under scope" do
|
241
|
+
Project.create(:name => "A", :state => :done)
|
242
|
+
Project.create(:name => "B", :state => :active)
|
243
|
+
Project.count.should eql(1)
|
244
|
+
end
|
245
|
+
|
246
|
+
end
|
247
|
+
|
282
248
|
describe "Mongoid stuff" do
|
283
249
|
|
284
250
|
it "test_symbolized_finder" do
|
@@ -288,12 +254,6 @@ describe "Symbolize" do
|
|
288
254
|
Person.where(status: :inactive).map(&:name).should eql(['Bob'])
|
289
255
|
end
|
290
256
|
|
291
|
-
# it "should work under scope" do
|
292
|
-
# Person.with_scope({ :status => :inactive }) do
|
293
|
-
# Person.all.map(&:name).should eql(['Bob'])
|
294
|
-
# end
|
295
|
-
# end
|
296
|
-
|
297
257
|
describe "dirty tracking / changed flag" do
|
298
258
|
before do
|
299
259
|
@anna = Person.where(name: 'Anna').first
|
metadata
CHANGED
@@ -5,8 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 4
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
8
|
+
- 4
|
9
|
+
segments_generated: true
|
10
|
+
version: 4.0.4
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Marcos Piccinini
|
@@ -14,12 +15,11 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-28 00:00:00 -02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: i18n
|
22
|
-
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
@@ -29,12 +29,13 @@ dependencies:
|
|
29
29
|
- 0
|
30
30
|
- 6
|
31
31
|
- 0
|
32
|
+
segments_generated: true
|
32
33
|
version: 0.6.0
|
33
34
|
type: :development
|
35
|
+
prerelease: false
|
34
36
|
version_requirements: *id001
|
35
37
|
- !ruby/object:Gem::Dependency
|
36
38
|
name: rspec
|
37
|
-
prerelease: false
|
38
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
@@ -42,14 +43,15 @@ dependencies:
|
|
42
43
|
- !ruby/object:Gem::Version
|
43
44
|
segments:
|
44
45
|
- 2
|
45
|
-
-
|
46
|
+
- 7
|
46
47
|
- 0
|
47
|
-
|
48
|
+
segments_generated: true
|
49
|
+
version: 2.7.0
|
48
50
|
type: :development
|
51
|
+
prerelease: false
|
49
52
|
version_requirements: *id002
|
50
53
|
- !ruby/object:Gem::Dependency
|
51
54
|
name: mongoid
|
52
|
-
prerelease: false
|
53
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
56
|
none: false
|
55
57
|
requirements:
|
@@ -58,13 +60,14 @@ dependencies:
|
|
58
60
|
segments:
|
59
61
|
- 2
|
60
62
|
- 3
|
61
|
-
-
|
62
|
-
|
63
|
+
- 0
|
64
|
+
segments_generated: true
|
65
|
+
version: 2.3.0
|
63
66
|
type: :development
|
67
|
+
prerelease: false
|
64
68
|
version_requirements: *id003
|
65
69
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
67
|
-
prerelease: false
|
70
|
+
name: activerecord
|
68
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
72
|
none: false
|
70
73
|
requirements:
|
@@ -74,8 +77,10 @@ dependencies:
|
|
74
77
|
- 3
|
75
78
|
- 1
|
76
79
|
- 1
|
80
|
+
segments_generated: true
|
77
81
|
version: 3.1.1
|
78
82
|
type: :development
|
83
|
+
prerelease: false
|
79
84
|
version_requirements: *id004
|
80
85
|
description: ActiveRecord/Mongoid enums with i18n
|
81
86
|
email: x@nofxx.com
|
@@ -98,6 +103,8 @@ files:
|
|
98
103
|
- spec/symbolize/active_record_spec.rb
|
99
104
|
- spec/symbolize/mongoid_spec.rb
|
100
105
|
- spec/db/001_create_testing_structure.rb
|
106
|
+
- spec/support/mongoid_models.rb
|
107
|
+
- spec/support/ar_models.rb
|
101
108
|
- spec/locales/pt.yml
|
102
109
|
- spec/locales/en.yml
|
103
110
|
- README.rdoc
|
@@ -116,8 +123,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
123
|
requirements:
|
117
124
|
- - ">="
|
118
125
|
- !ruby/object:Gem::Version
|
126
|
+
hash: 3271037607239981482
|
119
127
|
segments:
|
120
128
|
- 0
|
129
|
+
segments_generated: true
|
121
130
|
version: "0"
|
122
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
132
|
none: false
|
@@ -126,6 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
135
|
- !ruby/object:Gem::Version
|
127
136
|
segments:
|
128
137
|
- 0
|
138
|
+
segments_generated: true
|
129
139
|
version: "0"
|
130
140
|
requirements: []
|
131
141
|
|