mongoid-publishable 0.3.1 → 0.3.2
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/publishable.rb
CHANGED
@@ -83,6 +83,8 @@ module Mongoid
|
|
83
83
|
# mark as just published
|
84
84
|
run_after_publish_callbacks
|
85
85
|
end
|
86
|
+
# always return true
|
87
|
+
true
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
@@ -91,11 +93,6 @@ module Mongoid
|
|
91
93
|
def publish_via!(publisher)
|
92
94
|
publish_via(publisher) && save
|
93
95
|
end
|
94
|
-
|
95
|
-
# returns boolean of whether this instance has been published
|
96
|
-
def published?
|
97
|
-
persisted? && has_publisher_id? && meets_custom_publishing_conditions?
|
98
|
-
end
|
99
96
|
|
100
97
|
# returns boolean of whether this instance has been published
|
101
98
|
# regardless of whether it's been persisted yet
|
@@ -103,9 +100,14 @@ module Mongoid
|
|
103
100
|
has_publisher_id? && meets_custom_publishing_conditions?
|
104
101
|
end
|
105
102
|
|
103
|
+
# returns boolean of whether this instance has been published
|
104
|
+
def published?
|
105
|
+
persisted? && pre_published?
|
106
|
+
end
|
107
|
+
|
106
108
|
# returns whether this instance needs publishing (persisted, not published)
|
107
109
|
def requires_publishing?
|
108
|
-
persisted? &&
|
110
|
+
persisted? && !pre_published?
|
109
111
|
end
|
110
112
|
|
111
113
|
# returns whether or not the publisher is present
|
@@ -48,6 +48,10 @@ describe Mongoid::Publishable do
|
|
48
48
|
describe "an instance of a class that includes the module" do
|
49
49
|
subject { PublishableObject.new }
|
50
50
|
|
51
|
+
after(:each) do
|
52
|
+
subject.class.instance_variable_set(:"@publishing_conditions", nil)
|
53
|
+
end
|
54
|
+
|
51
55
|
describe "#publisher_column" do
|
52
56
|
it "should return :user_id by default" do
|
53
57
|
expect(subject.publisher_column).to eq :user_id
|
@@ -116,6 +120,20 @@ describe Mongoid::Publishable do
|
|
116
120
|
subject.stub(:save).and_return(true)
|
117
121
|
end
|
118
122
|
|
123
|
+
context "but with unmet custom publishing conditions" do
|
124
|
+
before(:each) do
|
125
|
+
subject.class.publishing_conditions do |object|
|
126
|
+
false
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should raise an exception" do
|
131
|
+
expect {
|
132
|
+
subject.persist_and_publish!(nil)
|
133
|
+
}.to raise_error(Mongoid::Publishable::UnpublishedError)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
119
137
|
context "but not published" do
|
120
138
|
it "should raise an exception" do
|
121
139
|
expect {
|
@@ -195,7 +213,19 @@ describe Mongoid::Publishable do
|
|
195
213
|
end
|
196
214
|
end
|
197
215
|
|
198
|
-
context "with custom publishing conditions" do
|
216
|
+
context "with met custom publishing conditions" do
|
217
|
+
before(:each) do
|
218
|
+
subject.class.publishing_conditions do |object|
|
219
|
+
true
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should return true" do
|
224
|
+
expect(subject.meets_custom_publishing_conditions?).to be_true
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context "with unmet custom publishing conditions" do
|
199
229
|
before(:each) do
|
200
230
|
subject.class.publishing_conditions do |object|
|
201
231
|
!!object.user_id
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-publishable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
@@ -183,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
segments:
|
185
185
|
- 0
|
186
|
-
hash:
|
186
|
+
hash: -1259240533369859954
|
187
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
188
|
none: false
|
189
189
|
requirements:
|
@@ -192,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
192
192
|
version: '0'
|
193
193
|
segments:
|
194
194
|
- 0
|
195
|
-
hash:
|
195
|
+
hash: -1259240533369859954
|
196
196
|
requirements: []
|
197
197
|
rubyforge_project:
|
198
198
|
rubygems_version: 1.8.24
|