mongoid_alize 0.3.1 → 0.4.0
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/lib/mongoid/alize/to_callback.rb +3 -3
- data/spec/mongoid/alize/callbacks/from/many_spec.rb +2 -2
- data/spec/mongoid/alize/callbacks/from/one_spec.rb +2 -3
- data/spec/mongoid/alize/callbacks/to/many_from_many_spec.rb +2 -3
- data/spec/mongoid/alize/callbacks/to/many_from_one_spec.rb +2 -3
- data/spec/mongoid/alize/callbacks/to/one_from_many_spec.rb +2 -2
- data/spec/mongoid/alize/callbacks/to/one_from_one_spec.rb +4 -6
- data/spec/mongoid_alize_spec.rb +3 -3
- data/spec/spec_helper.rb +12 -2
- metadata +6 -6
@@ -85,7 +85,7 @@ module Mongoid
|
|
85
85
|
":#{inverse_relation}_fields"
|
86
86
|
else
|
87
87
|
<<-RUBIES
|
88
|
-
(#{find_relation}
|
88
|
+
(#{find_relation}.name.to_s + '_fields')
|
89
89
|
RUBIES
|
90
90
|
end
|
91
91
|
end
|
@@ -99,13 +99,13 @@ module Mongoid
|
|
99
99
|
end
|
100
100
|
else
|
101
101
|
<<-RUBIES
|
102
|
-
(#{find_relation}
|
102
|
+
(#{find_relation}.relation.superclass == Mongoid::Relations::One)
|
103
103
|
RUBIES
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
def find_relation
|
108
|
-
"relation.class.relations.find { |
|
108
|
+
"relation.class.relations.values.find { |metadata| metadata.inverse(self) == :#{relation} && metadata.class_name == self.class.name }"
|
109
109
|
end
|
110
110
|
|
111
111
|
def iterable_relation
|
@@ -47,14 +47,14 @@ describe Mongoid::Alize::Callbacks::From::Many do
|
|
47
47
|
{ "_id" => @person.id,
|
48
48
|
"name"=> "Bob",
|
49
49
|
"location" => "Paris",
|
50
|
-
"created_at"=> @now
|
50
|
+
"created_at" => @now }
|
51
51
|
end
|
52
52
|
|
53
53
|
before do
|
54
54
|
now = Time.now
|
55
55
|
stub(Time).now { now }
|
56
56
|
@head = Head.create
|
57
|
-
@person = Person.create(:name => "Bob"
|
57
|
+
@person = Person.create(:name => "Bob")
|
58
58
|
|
59
59
|
@head.relations["wanted_by"].should be_stores_foreign_key
|
60
60
|
end
|
@@ -48,13 +48,12 @@ describe Mongoid::Alize::Callbacks::From::One do
|
|
48
48
|
def person_fields
|
49
49
|
{ "name"=> "Bob",
|
50
50
|
"location" => "Paris",
|
51
|
-
"created_at"=> @now
|
51
|
+
"created_at"=> @now }
|
52
52
|
end
|
53
53
|
|
54
54
|
def create_models
|
55
55
|
@head = Head.create
|
56
|
-
@person = Person.create(:name => @name = "Bob"
|
57
|
-
:created_at => @now = Time.now)
|
56
|
+
@person = Person.create(:name => @name = "Bob")
|
58
57
|
end
|
59
58
|
|
60
59
|
before do
|
@@ -17,7 +17,7 @@ describe Mongoid::Alize::ToCallback do
|
|
17
17
|
{ "_id" => @person.id,
|
18
18
|
"name" => "Bob",
|
19
19
|
"location" => "Paris",
|
20
|
-
"created_at"=> @now
|
20
|
+
"created_at" => @now }
|
21
21
|
end
|
22
22
|
|
23
23
|
def other_wanted_by
|
@@ -26,8 +26,7 @@ describe Mongoid::Alize::ToCallback do
|
|
26
26
|
|
27
27
|
def create_models
|
28
28
|
@head = Head.create(
|
29
|
-
:wanted_by => [@person = Person.create(:name => "Bob"
|
30
|
-
:created_at => @now = Time.now)])
|
29
|
+
:wanted_by => [@person = Person.create(:name => "Bob")])
|
31
30
|
@person.wants = [@head]
|
32
31
|
end
|
33
32
|
|
@@ -19,8 +19,7 @@ describe Mongoid::Alize::ToCallback do
|
|
19
19
|
describe "with metadata in advance" do
|
20
20
|
def create_models
|
21
21
|
@head = Head.create(
|
22
|
-
:sees => [@person = Person.create(:name => "Bob"
|
23
|
-
:created_at => @now = Time.now)])
|
22
|
+
:sees => [@person = Person.create(:name => "Bob")])
|
24
23
|
@person.seen_by = @head
|
25
24
|
end
|
26
25
|
|
@@ -32,7 +31,7 @@ describe Mongoid::Alize::ToCallback do
|
|
32
31
|
{ "_id" => @person.id,
|
33
32
|
"name"=> "Bob",
|
34
33
|
"location" => "Paris",
|
35
|
-
"created_at"=> @now
|
34
|
+
"created_at"=> @now }
|
36
35
|
end
|
37
36
|
|
38
37
|
def other_see
|
@@ -19,7 +19,7 @@ describe Mongoid::Alize::ToCallback do
|
|
19
19
|
describe "with metadata in advance" do
|
20
20
|
def create_models
|
21
21
|
@head = Head.create(
|
22
|
-
:captor => @person = Person.create(:name => "Bob"
|
22
|
+
:captor => @person = Person.create(:name => "Bob"))
|
23
23
|
@person.heads = [@head]
|
24
24
|
end
|
25
25
|
|
@@ -37,7 +37,7 @@ describe Mongoid::Alize::ToCallback do
|
|
37
37
|
def captor_fields
|
38
38
|
{ "name"=> "Bob",
|
39
39
|
"location" => "Paris",
|
40
|
-
"created_at"=> @now
|
40
|
+
"created_at"=> @now }
|
41
41
|
end
|
42
42
|
|
43
43
|
def run_callback
|
@@ -23,8 +23,7 @@ describe Mongoid::Alize::ToCallback do
|
|
23
23
|
|
24
24
|
def create_models
|
25
25
|
@head = Head.create(
|
26
|
-
:person => @person = Person.create(:name => "Bob"
|
27
|
-
:created_at => @now = Time.now))
|
26
|
+
:person => @person = Person.create(:name => "Bob"))
|
28
27
|
end
|
29
28
|
|
30
29
|
before do
|
@@ -37,7 +36,7 @@ describe Mongoid::Alize::ToCallback do
|
|
37
36
|
def person_fields
|
38
37
|
{ "name"=> "Bob",
|
39
38
|
"location" => "Paris",
|
40
|
-
"created_at"=> @now
|
39
|
+
"created_at"=> @now }
|
41
40
|
end
|
42
41
|
|
43
42
|
def run_callback
|
@@ -84,8 +83,7 @@ describe Mongoid::Alize::ToCallback do
|
|
84
83
|
|
85
84
|
def create_models
|
86
85
|
@head = Head.create(
|
87
|
-
:nearest => @person = Person.create(:name => @name = "Bob"
|
88
|
-
:created_at => @now = Time.now))
|
86
|
+
:nearest => @person = Person.create(:name => @name = "Bob"))
|
89
87
|
end
|
90
88
|
|
91
89
|
before do
|
@@ -98,7 +96,7 @@ describe Mongoid::Alize::ToCallback do
|
|
98
96
|
def nearest_fields
|
99
97
|
{ "name"=> "Bob",
|
100
98
|
"location" => "Paris",
|
101
|
-
"created_at"=> @now
|
99
|
+
"created_at"=> @now }
|
102
100
|
end
|
103
101
|
|
104
102
|
def run_callback
|
data/spec/mongoid_alize_spec.rb
CHANGED
@@ -84,7 +84,7 @@ describe Mongoid::Alize do
|
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should push data to person" do
|
87
|
-
@head.update_attributes!(:size => @size =
|
87
|
+
@head.update_attributes!(:size => @size = 20)
|
88
88
|
assert_person
|
89
89
|
end
|
90
90
|
|
@@ -394,7 +394,7 @@ describe Mongoid::Alize do
|
|
394
394
|
before do
|
395
395
|
Head.send(:alize, :below_people, :fields => lambda { |inverse|
|
396
396
|
self.alize_fields(inverse) })
|
397
|
-
@head.below_people
|
397
|
+
@head.below_people << @person
|
398
398
|
end
|
399
399
|
|
400
400
|
def assert_head
|
@@ -500,7 +500,7 @@ describe Mongoid::Alize do
|
|
500
500
|
before do
|
501
501
|
fields = { :fields => lambda { |inverse| [:name, :location] } }
|
502
502
|
Head.send(:alize, :below_people, fields)
|
503
|
-
@head.below_people
|
503
|
+
@head.below_people << @person
|
504
504
|
@head.save!
|
505
505
|
end
|
506
506
|
|
data/spec/spec_helper.rb
CHANGED
@@ -4,9 +4,19 @@ require 'awesome_print'
|
|
4
4
|
require 'wirble'
|
5
5
|
require 'mongoid'
|
6
6
|
|
7
|
+
def three?
|
8
|
+
Mongoid::VERSION =~ /^3/
|
9
|
+
end
|
10
|
+
|
7
11
|
Mongoid.configure do |config|
|
8
|
-
|
12
|
+
if three?
|
13
|
+
config.connect_to("mongoid_alize_test")
|
14
|
+
Moped.logger = Logger.new("log/test.log")
|
15
|
+
Moped.logger.level = Logger::DEBUG
|
16
|
+
else
|
17
|
+
config.master = Mongo::Connection.new("localhost", 27017,
|
9
18
|
:logger => Logger.new("log/test.log")).db("mongoid_alize_test")
|
19
|
+
end
|
10
20
|
end
|
11
21
|
|
12
22
|
require File.expand_path("../../lib/mongoid_alize", __FILE__)
|
@@ -18,7 +28,7 @@ RSpec.configure do |config|
|
|
18
28
|
|
19
29
|
config.mock_with :rr
|
20
30
|
config.before :each do
|
21
|
-
Mongoid.
|
31
|
+
Mongoid.purge!
|
22
32
|
|
23
33
|
persistent_fields = {
|
24
34
|
Object => [:_id, :_type],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_alize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '2'
|
21
|
+
version: '2.4'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '2'
|
29
|
+
version: '2.4'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rspec
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|