join_collection 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/lib/join_collection.rb +7 -3
- data/spec/join_collection_spec.rb +18 -13
- metadata +16 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c959fb846f69b717c9296d2fb1550e07f84b21de
|
4
|
+
data.tar.gz: f57b7d583022527eed13751bc7b9b6923341dd8d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8363bf466e25b65d12754f923340f4e10fe0221a0a1ae42308a841fa7a0155c8f6e9d8980d6e45e0e83727a15ff70a41cfb12f5327ceb238f289bacb8b2a4ef9
|
7
|
+
data.tar.gz: b08651f340cc25657c5a8c3c656bc56dd683493c89a76c58168f3a6b9d19b50abb9390f627a3711c9d49708db5543bd5bba3a703e6c7a97f53f46e83a5fcf556
|
data/.gitignore
CHANGED
data/lib/join_collection.rb
CHANGED
@@ -2,9 +2,13 @@ require 'mongoid'
|
|
2
2
|
|
3
3
|
class JoinCollection
|
4
4
|
|
5
|
-
VERSION = "0.
|
5
|
+
VERSION = "0.3.0"
|
6
|
+
|
7
|
+
class Doc
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::Attributes::Dynamic
|
10
|
+
end
|
6
11
|
|
7
|
-
class Doc; include Mongoid::Document; end
|
8
12
|
|
9
13
|
attr_reader :source_objects
|
10
14
|
attr_accessor :join_type, :singular_target, :plural_target
|
@@ -82,7 +86,7 @@ class JoinCollection
|
|
82
86
|
when plural_target
|
83
87
|
doc[plural_target] = target_objects if join_type == :join_many
|
84
88
|
else
|
85
|
-
doc["#{singular_target}_#{field}"] = target_object.try(field)
|
89
|
+
doc["#{singular_target}_#{field}"] = target_object.try!(field)
|
86
90
|
end
|
87
91
|
end
|
88
92
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
class User
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Attributes::Dynamic
|
6
|
+
end
|
7
|
+
class Post
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::Attributes::Dynamic
|
10
|
+
end
|
6
11
|
|
7
12
|
describe JoinCollection do
|
8
13
|
let!(:user1) { User.new :mysql_id => 1, :name => 'Bob' }
|
@@ -31,11 +36,11 @@ describe JoinCollection do
|
|
31
36
|
describe '#join_to' do
|
32
37
|
before do
|
33
38
|
@post_collection = JoinCollection.new([post1])
|
34
|
-
User.
|
39
|
+
allow(User).to receive(:where).and_return([user1])
|
35
40
|
end
|
36
41
|
|
37
42
|
it 'should call User.where' do
|
38
|
-
User.
|
43
|
+
expect(User).to receive(:where).with(:mysql_id.in => [1]).and_return([user1])
|
39
44
|
@post_collection.join_to(:user, User, :relation => {:user_id => :mysql_id}, :delegation => {:fields => [:mysql_id]})
|
40
45
|
end
|
41
46
|
|
@@ -60,11 +65,11 @@ describe JoinCollection do
|
|
60
65
|
describe '#join_one' do
|
61
66
|
before do
|
62
67
|
@user_collection = JoinCollection.new([user1])
|
63
|
-
Post.
|
68
|
+
allow(Post).to receive(:where).and_return([post1])
|
64
69
|
end
|
65
70
|
|
66
71
|
it 'should call Post.where' do
|
67
|
-
Post.
|
72
|
+
expect(Post).to receive(:where).with(:user_id.in => [1]).and_return([post1])
|
68
73
|
@user_collection.join_one(:post, Post, :relation => {:user_id => :mysql_id}, :delegation => {:fields => [:mysql_id]})
|
69
74
|
end
|
70
75
|
|
@@ -89,7 +94,7 @@ describe JoinCollection do
|
|
89
94
|
describe '#join_many' do
|
90
95
|
before do
|
91
96
|
@user_collection = JoinCollection.new([user2])
|
92
|
-
Post.
|
97
|
+
allow(Post).to receive(:where).and_return([post2, post3])
|
93
98
|
end
|
94
99
|
|
95
100
|
it 'should catch the whole target objects if the delegation field name equals to the plural target name' do
|
@@ -102,7 +107,7 @@ describe JoinCollection do
|
|
102
107
|
@user_collection.join_many(:post, Post,
|
103
108
|
:relation => {:user_id => :mysql_id}, :delegation => {:fields => [:content, :published]})
|
104
109
|
expect(@user_collection.source_objects.first.post_content).to eq('text 2')
|
105
|
-
expect(@user_collection.source_objects.first.post_published).to
|
110
|
+
expect(@user_collection.source_objects.first.post_published).to be_truthy
|
106
111
|
end
|
107
112
|
|
108
113
|
it 'should have correct values in delegation fields if a conditional block given' do
|
@@ -110,14 +115,14 @@ describe JoinCollection do
|
|
110
115
|
:relation => {:user_id => :mysql_id},
|
111
116
|
:delegation => {:if => lambda { |x| x.published == false }, :fields => [:content, :published]})
|
112
117
|
expect(@user_collection.source_objects.first.post_content).to eq('text 3')
|
113
|
-
expect(@user_collection.source_objects.first.post_published).to
|
118
|
+
expect(@user_collection.source_objects.first.post_published).to be_falsey
|
114
119
|
end
|
115
120
|
end
|
116
121
|
|
117
122
|
context 'source objects are hash objects' do
|
118
123
|
it 'can still join to target object' do
|
119
124
|
user = User.new(:mysql_id => 1, :name => 'Bob')
|
120
|
-
User.
|
125
|
+
allow(User).to receive(:where).and_return([user])
|
121
126
|
|
122
127
|
post = {:mysql_id => 1, :user_id => 1, :content => 'text 1', :published => true}
|
123
128
|
post_collection = JoinCollection.new([post])
|
@@ -127,7 +132,7 @@ describe JoinCollection do
|
|
127
132
|
|
128
133
|
it 'can still join one target object' do
|
129
134
|
post = Post.new(:mysql_id => 1, :user_id => 1, :content => 'text 1', :published => true)
|
130
|
-
Post.
|
135
|
+
allow(Post).to receive(:where).and_return([post])
|
131
136
|
|
132
137
|
user = {:mysql_id => 1, :name => 'Bob'}
|
133
138
|
user_collection = JoinCollection.new([user])
|
@@ -137,7 +142,7 @@ describe JoinCollection do
|
|
137
142
|
|
138
143
|
it 'can still join many target objects' do
|
139
144
|
post = Post.new(:mysql_id => 1, :user_id => 1, :content => 'text 1', :published => true)
|
140
|
-
Post.
|
145
|
+
allow(Post).to receive(:where).and_return([post])
|
141
146
|
|
142
147
|
user = {:mysql_id => 1, :name => 'Bob'}
|
143
148
|
user_collection = JoinCollection.new([user])
|
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: join_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mason Chang
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongoid
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '1.3'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '1.3'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rspec
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Joining mongoid docs with specified relation
|
@@ -82,7 +73,7 @@ executables: []
|
|
82
73
|
extensions: []
|
83
74
|
extra_rdoc_files: []
|
84
75
|
files:
|
85
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
86
77
|
- Gemfile
|
87
78
|
- LICENSE.txt
|
88
79
|
- README.md
|
@@ -94,33 +85,26 @@ files:
|
|
94
85
|
homepage: https://github.com/optimis/join_collection
|
95
86
|
licenses:
|
96
87
|
- MIT
|
88
|
+
metadata: {}
|
97
89
|
post_install_message:
|
98
90
|
rdoc_options: []
|
99
91
|
require_paths:
|
100
92
|
- lib
|
101
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
94
|
requirements:
|
104
|
-
- -
|
95
|
+
- - ">="
|
105
96
|
- !ruby/object:Gem::Version
|
106
97
|
version: '0'
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
hash: 3529857739931548642
|
110
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
99
|
requirements:
|
113
|
-
- -
|
100
|
+
- - ">="
|
114
101
|
- !ruby/object:Gem::Version
|
115
102
|
version: '0'
|
116
|
-
segments:
|
117
|
-
- 0
|
118
|
-
hash: 3529857739931548642
|
119
103
|
requirements: []
|
120
104
|
rubyforge_project:
|
121
|
-
rubygems_version:
|
105
|
+
rubygems_version: 2.2.3
|
122
106
|
signing_key:
|
123
|
-
specification_version:
|
107
|
+
specification_version: 4
|
124
108
|
summary: Joining mongoid docs with specified relation
|
125
109
|
test_files:
|
126
110
|
- spec/join_collection_spec.rb
|