has_moderated 0.0.34 → 1.0.alpha
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/README.rdoc +17 -0
- data/lib/generators/has_moderated/install/templates/migration.rb +4 -3
- data/lib/has_moderated/adapters/active_record.rb +109 -0
- data/lib/has_moderated/adapters/proxy.rb +23 -0
- data/lib/has_moderated/associations/base.rb +157 -0
- data/lib/has_moderated/associations/collection.rb +123 -0
- data/lib/has_moderated/associations/has_many.rb +15 -0
- data/lib/has_moderated/associations/has_one.rb +58 -0
- data/lib/has_moderated/carrier_wave.rb +3 -3
- data/lib/has_moderated/common.rb +62 -113
- data/lib/has_moderated/moderated_attributes.rb +24 -11
- data/lib/has_moderated/moderated_create.rb +22 -14
- data/lib/has_moderated/moderated_destroy.rb +11 -10
- data/lib/has_moderated/moderation_model.rb +6 -200
- data/lib/has_moderated/user_hooks.rb +3 -2
- data/lib/has_moderated/version.rb +1 -1
- data/lib/has_moderated.rb +15 -7
- data/test/dummy/app/models/moderation.rb +0 -0
- data/test/dummy/app/models/subtask.rb +0 -1
- data/test/dummy/app/models/task.rb +0 -13
- data/test/dummy/app/models/task_connection.rb +4 -0
- data/test/dummy/db/migrate/20120515155730_create_moderations2.rb +20 -0
- data/test/dummy/db/migrate/20120515174306_prepare_for_new_tests.rb +36 -0
- data/test/dummy/db/migrate/20120515175621_remove_photo_relateds.rb +8 -0
- data/test/dummy/db/schema.rb +17 -96
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +35 -0
- data/test/dummy/log/test.log +81290 -0
- data/test/dummy/spec/models/task_spec.rb +414 -247
- data/test/dummy/spec/spec_helper.rb +4 -0
- metadata +26 -57
- data/lib/has_moderated/moderated_associations.rb +0 -69
- data/test/dummy/app/models/habtm_name_test.rb +0 -3
- data/test/dummy/app/models/hjoin_test.rb +0 -3
- data/test/dummy/app/models/hmany_fk_test.rb +0 -3
- data/test/dummy/app/models/hmanythrough_join.rb +0 -4
- data/test/dummy/app/models/hmanythrough_test.rb +0 -4
- data/test/dummy/app/models/hone_as_test.rb +0 -3
- data/test/dummy/app/models/hone_test.rb +0 -3
- data/test/dummy/app/models/hook_test.rb +0 -9
- data/test/dummy/app/models/photo.rb +0 -8
- data/test/dummy/app/models/photo_holder.rb +0 -4
- data/test/dummy/app/models/photo_related.rb +0 -3
- data/test/dummy/app/models/task_all.rb +0 -4
- data/test/dummy/app/models/task_photo.rb +0 -5
- data/test/dummy/spec/models/habtm_name_test_spec.rb +0 -22
- data/test/dummy/spec/models/hjoin_test_spec.rb +0 -54
- data/test/dummy/spec/models/hmany_fk_test_spec.rb +0 -36
- data/test/dummy/spec/models/hmanythrough_test_spec.rb +0 -99
- data/test/dummy/spec/models/hone_as_test_spec.rb +0 -36
- data/test/dummy/spec/models/hone_test_spec.rb +0 -36
- data/test/dummy/spec/models/hooks_spec.rb +0 -30
- data/test/dummy/spec/models/photo_holder_spec.rb +0 -21
- data/test/dummy/spec/models/photo_spec.rb +0 -69
- data/test/dummy/spec/models/task_photo_spec.rb +0 -25
|
@@ -1,272 +1,439 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Task do
|
|
4
|
-
it "doesn't store new tasks in the database, but in moderations" do
|
|
5
|
-
Task.create! :title => "Bye Bye"
|
|
6
|
-
Task.count.should eq(0)
|
|
7
|
-
Moderation.count.should eq(1)
|
|
8
|
-
end
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# test different ways (will generate more than one moderation)
|
|
26
|
-
# 1
|
|
27
|
-
Task.last.update_attributes(:title => "Hollywood Hills")
|
|
28
|
-
# 2
|
|
29
|
-
t = Task.last
|
|
30
|
-
t.title = "Hollywood Hills"
|
|
31
|
-
t.save
|
|
32
|
-
# 3
|
|
33
|
-
Task.last.update_attribute(:title, "Hollywood Hills")
|
|
34
|
-
# 4
|
|
35
|
-
t = Task.last
|
|
36
|
-
t.attributes = { :title => "Hollywood Hills" }
|
|
37
|
-
t.save
|
|
38
|
-
|
|
39
|
-
Moderation.count.should eq(4)
|
|
40
|
-
|
|
41
|
-
Task.last.title.should eq("Bye Bye")
|
|
42
|
-
Moderation.last.accept
|
|
43
|
-
Task.last.title.should eq("Hollywood Hills")
|
|
44
|
-
Task.count.should eq(1)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "properly discards a create moderation" do
|
|
48
|
-
Task.create! :title => "Bye Bye"
|
|
49
|
-
Moderation.last.discard
|
|
50
|
-
|
|
51
|
-
Task.count.should eq(0)
|
|
52
|
-
Moderation.count.should eq(0)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "properly discards an update moderation" do
|
|
56
|
-
Task.create! :title => "Bye Bye"
|
|
57
|
-
Moderation.last.accept
|
|
58
|
-
|
|
59
|
-
Task.last.update_attributes(:title => "Hollywood Hills")
|
|
60
|
-
|
|
61
|
-
Moderation.last.discard
|
|
62
|
-
|
|
63
|
-
Task.count.should eq(1)
|
|
64
|
-
Task.last.title.should eq("Bye Bye")
|
|
65
|
-
Moderation.count.should eq(0)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "properly stores an associated subtask in moderations" do
|
|
69
|
-
t = Task.new :title => "Bye Bye"
|
|
70
|
-
t.subtasks.build :title => "Hollywood Hills"
|
|
71
|
-
t.save
|
|
72
|
-
|
|
73
|
-
Task.count.should eq(0)
|
|
74
|
-
Subtask.count.should eq(0)
|
|
75
|
-
|
|
76
|
-
Moderation.last.accept
|
|
77
|
-
Moderation.count.should eq(0)
|
|
78
|
-
|
|
79
|
-
t = Task.last
|
|
80
|
-
t.title.should eq("Bye Bye")
|
|
81
|
-
t.subtasks.count.should eq(1)
|
|
82
|
-
t.subtasks.first.title.should eq("Hollywood Hills")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "bypasses attr_accessible when applying a create moderation" do
|
|
86
|
-
# desc is not attr_accessible, can't use mass assign to create
|
|
87
|
-
t = Task.new :title => "Bye Bye"
|
|
88
|
-
t.desc = "Hollywood Hills"
|
|
89
|
-
t.save
|
|
5
|
+
#
|
|
6
|
+
# has_moderated_association
|
|
7
|
+
# has_many
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
context "has_many association:" do
|
|
11
|
+
before do
|
|
12
|
+
Object.send(:remove_const, 'Task')
|
|
13
|
+
load 'task.rb'
|
|
14
|
+
Object.send(:remove_const, 'Subtask')
|
|
15
|
+
load 'subtask.rb'
|
|
16
|
+
# TODO: set very obscure options
|
|
17
|
+
Task.has_many :renamed_subtasks, :class_name => "Subtask"
|
|
18
|
+
Task.has_moderated_association :renamed_subtasks
|
|
19
|
+
end
|
|
90
20
|
|
|
91
|
-
|
|
21
|
+
it "creates and associates subtask (create)" do
|
|
22
|
+
task = Task.create! :title => "Task 1"
|
|
23
|
+
Moderation.count.should eq(0)
|
|
24
|
+
task.renamed_subtasks.create! :title => "Subtask 1"
|
|
92
25
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
Moderation.count.should eq(0)
|
|
96
|
-
Task.last.title.should eq("Bye Bye") # just so we know it's created properly
|
|
97
|
-
Task.last.desc.should eq("Hollywood Hills")
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "bypasses attr_accessible when applying an update moderation" do
|
|
101
|
-
Task.create! :title => "Bye Bye"
|
|
102
|
-
Moderation.last.accept
|
|
103
|
-
|
|
104
|
-
# desc is not attr_accessible
|
|
105
|
-
t = Task.last
|
|
106
|
-
t.desc = "Hollywood Hills"
|
|
107
|
-
t.save
|
|
108
|
-
|
|
109
|
-
Moderation.count.should eq(1)
|
|
110
|
-
|
|
111
|
-
Task.last.desc.should be_nil
|
|
112
|
-
Moderation.last.accept
|
|
113
|
-
Task.last.desc.should eq("Hollywood Hills")
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it "remembers associations to existing records on create" do
|
|
117
|
-
subtask = Subtask.create! :title => "Bye Bye"
|
|
118
|
-
Subtask.count.should eq(1)
|
|
119
|
-
|
|
120
|
-
t = Task.new :title => "Hollywood Hills"
|
|
121
|
-
t.subtasks << subtask
|
|
122
|
-
t.save
|
|
123
|
-
|
|
124
|
-
Task.count.should eq(0)
|
|
125
|
-
Subtask.first.task.should be_nil
|
|
126
|
-
|
|
127
|
-
Moderation.last.accept
|
|
128
|
-
Subtask.first.task.should_not be_nil
|
|
129
|
-
t = Task.first
|
|
130
|
-
t.subtasks.count.should eq(1)
|
|
131
|
-
t.subtasks.first.title.should eq("Bye Bye")
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it "accepts :all for has_moderated_create's :with_associations option" do
|
|
135
|
-
t = TaskAll.new :title => "Bye Bye"
|
|
136
|
-
t.subtasks.build :title => "Hollywood Hills"
|
|
137
|
-
t.save
|
|
138
|
-
|
|
139
|
-
TaskAll.count.should eq(0)
|
|
140
|
-
Subtask.count.should eq(0)
|
|
141
|
-
|
|
142
|
-
Moderation.last.accept
|
|
26
|
+
task = Task.first
|
|
27
|
+
task.renamed_subtasks.count.should eq(0)
|
|
143
28
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
subtask = Subtask.create! :title => "Bye Bye"
|
|
152
|
-
Subtask.count.should eq(1)
|
|
153
|
-
|
|
154
|
-
t = Task.new :title => "Hollywood Hills"
|
|
155
|
-
t.subtasks << subtask
|
|
156
|
-
t.save
|
|
157
|
-
|
|
158
|
-
Task.count.should eq(0)
|
|
159
|
-
Subtask.delete_all
|
|
160
|
-
Subtask.count.should eq(0)
|
|
29
|
+
Moderation.count.should eq(1)
|
|
30
|
+
Moderation.last.accept
|
|
31
|
+
Moderation.count.should eq(0)
|
|
32
|
+
|
|
33
|
+
subtask = Task.first.renamed_subtasks.first
|
|
34
|
+
subtask.title.should eq("Subtask 1")
|
|
35
|
+
end
|
|
161
36
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
it "moderates destroy" do
|
|
168
|
-
Task.create! :title => "Bye Bye"
|
|
169
|
-
Moderation.last.accept
|
|
37
|
+
it "creates and associates subtask (build, save task)" do
|
|
38
|
+
task = Task.create! :title => "Task 1"
|
|
39
|
+
Moderation.count.should eq(0)
|
|
40
|
+
task.renamed_subtasks.build :title => "Subtask 1"
|
|
41
|
+
task.save
|
|
170
42
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
43
|
+
task = Task.first
|
|
44
|
+
task.renamed_subtasks.count.should eq(0)
|
|
45
|
+
|
|
46
|
+
Moderation.count.should eq(1)
|
|
47
|
+
Moderation.last.accept
|
|
48
|
+
Moderation.count.should eq(0)
|
|
49
|
+
|
|
50
|
+
subtask = Task.first.renamed_subtasks.first
|
|
51
|
+
subtask.title.should eq("Subtask 1")
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "creates and associates subtask (build, save subtask)", :broken => true do
|
|
55
|
+
task = Task.create! :title => "Task 1"
|
|
56
|
+
Moderation.count.should eq(0)
|
|
57
|
+
subtask = task.renamed_subtasks.build :title => "Subtask 1"
|
|
58
|
+
subtask.save
|
|
59
|
+
|
|
60
|
+
task = Task.first
|
|
61
|
+
task.renamed_subtasks.count.should eq(0)
|
|
62
|
+
|
|
63
|
+
Moderation.count.should eq(1)
|
|
64
|
+
Moderation.last.accept
|
|
65
|
+
Moderation.count.should eq(0)
|
|
66
|
+
|
|
67
|
+
subtask = Task.first.renamed_subtasks.first
|
|
68
|
+
subtask.title.should eq("Subtask 1")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "associates (<<) existing subtask" do
|
|
72
|
+
task = Task.create! :title => "Task 1"
|
|
73
|
+
Subtask.create! :title => "Subtask 1"
|
|
74
|
+
Moderation.count.should eq(0)
|
|
75
|
+
task.renamed_subtasks << Subtask.first
|
|
76
|
+
|
|
77
|
+
task = Task.first
|
|
78
|
+
task.renamed_subtasks.count.should eq(0)
|
|
79
|
+
|
|
80
|
+
Moderation.count.should eq(1)
|
|
81
|
+
Moderation.last.accept
|
|
82
|
+
Moderation.count.should eq(0)
|
|
83
|
+
|
|
84
|
+
subtask = Task.first.renamed_subtasks.first
|
|
85
|
+
subtask.title.should eq("Subtask 1")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "associates (push) existing subtask" do
|
|
89
|
+
task = Task.create! :title => "Task 1"
|
|
90
|
+
Subtask.create! :title => "Subtask 1"
|
|
91
|
+
Moderation.count.should eq(0)
|
|
92
|
+
task.renamed_subtasks.push Subtask.first
|
|
93
|
+
|
|
94
|
+
task = Task.first
|
|
95
|
+
task.renamed_subtasks.count.should eq(0)
|
|
96
|
+
|
|
97
|
+
Moderation.count.should eq(1)
|
|
98
|
+
Moderation.last.accept
|
|
99
|
+
Moderation.count.should eq(0)
|
|
100
|
+
|
|
101
|
+
subtask = Task.first.renamed_subtasks.first
|
|
102
|
+
subtask.title.should eq("Subtask 1")
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "moderates deleting association" do
|
|
106
|
+
task = Task.create! :title => "Task 1"
|
|
107
|
+
task.renamed_subtasks.create! :title => "Subtask 1"
|
|
108
|
+
Moderation.last.accept
|
|
109
|
+
|
|
110
|
+
Task.last.renamed_subtasks.delete(Task.last.renamed_subtasks.last)
|
|
111
|
+
Task.last.renamed_subtasks.count.should eq(1)
|
|
112
|
+
|
|
113
|
+
Moderation.last.accept
|
|
114
|
+
Task.last.renamed_subtasks.count.should eq(0)
|
|
115
|
+
end
|
|
178
116
|
end
|
|
179
117
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
118
|
+
#
|
|
119
|
+
# has_moderated_association
|
|
120
|
+
# has_and_belongs_to_many
|
|
121
|
+
#
|
|
122
|
+
|
|
123
|
+
context "has_and_belongs_to_many association:" do
|
|
124
|
+
before do
|
|
125
|
+
Object.send(:remove_const, 'Task')
|
|
126
|
+
load 'task.rb'
|
|
127
|
+
Object.send(:remove_const, 'Subtask')
|
|
128
|
+
load 'subtask.rb'
|
|
129
|
+
# TODO: set very obscure options
|
|
130
|
+
Task.has_and_belongs_to_many :renamed_subtasks, :class_name => "Subtask", :join_table => "tasks_jointable", :foreign_key => "m1_id", :association_foreign_key => "m2_id"
|
|
131
|
+
Task.has_moderated_association :renamed_subtasks
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "creates and associates subtask (create)", :broken => true do
|
|
135
|
+
task = Task.create! :title => "Task 1"
|
|
136
|
+
Moderation.count.should eq(0)
|
|
137
|
+
task.renamed_subtasks.create! :title => "Subtask 1"
|
|
138
|
+
|
|
139
|
+
task = Task.first
|
|
140
|
+
Subtask.count.should eq(0)
|
|
141
|
+
task.renamed_subtasks.count.should eq(0)
|
|
142
|
+
|
|
143
|
+
Moderation.count.should eq(1)
|
|
144
|
+
Moderation.last.accept
|
|
145
|
+
Moderation.count.should eq(0)
|
|
146
|
+
|
|
147
|
+
subtask = Task.first.renamed_subtasks.first
|
|
148
|
+
subtask.title.should eq("Subtask 1")
|
|
149
|
+
end
|
|
195
150
|
end
|
|
196
151
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
152
|
+
#
|
|
153
|
+
# has_moderated_association
|
|
154
|
+
# has_many :through
|
|
155
|
+
#
|
|
156
|
+
|
|
157
|
+
context "has_many :through association:" do
|
|
158
|
+
before do
|
|
159
|
+
Object.send(:remove_const, 'Task')
|
|
160
|
+
load 'task.rb'
|
|
161
|
+
Object.send(:remove_const, 'Subtask')
|
|
162
|
+
load 'subtask.rb'
|
|
163
|
+
# TODO: set very obscure options
|
|
164
|
+
Task.has_many :renamed_connections, :class_name => "TaskConnection", :foreign_key => "m1_id"
|
|
165
|
+
Task.has_many :renamed_subtasks, :class_name => "Subtask", :through => :renamed_connections, :source => :renamed_subtask
|
|
166
|
+
Subtask.has_many :renamed_connections, :class_name => "TaskConnection", :foreign_key => "m2_id"
|
|
167
|
+
Subtask.has_many :renamed_tasks, :class_name => "Task", :through => :renamed_connections, :source => :renamed_task
|
|
168
|
+
Task.has_moderated_association :renamed_subtasks
|
|
169
|
+
Task.has_moderated_association :renamed_connections
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
it "associates subtask 1 (update)" do
|
|
173
|
+
task = Task.create! :title => "Task 1"
|
|
174
|
+
Moderation.count.should eq(0)
|
|
175
|
+
|
|
176
|
+
conn = TaskConnection.new :title => "Connection 1"
|
|
177
|
+
conn.renamed_subtask = Subtask.new :title => "Subtask 1"
|
|
178
|
+
task.renamed_connections << conn
|
|
179
|
+
task.save
|
|
180
|
+
|
|
181
|
+
TaskConnection.count.should eq(0)
|
|
182
|
+
Subtask.count.should eq(0)
|
|
183
|
+
|
|
184
|
+
Moderation.last.accept
|
|
185
|
+
Moderation.count.should eq(0)
|
|
186
|
+
|
|
187
|
+
subtask = Task.first.renamed_subtasks.first
|
|
188
|
+
subtask.title.should eq("Subtask 1")
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "associates subtask 2 (update)" do
|
|
192
|
+
task = Task.create! :title => "Task 1"
|
|
193
|
+
Moderation.count.should eq(0)
|
|
194
|
+
|
|
195
|
+
task.renamed_subtasks.build :title => "Subtask 1"
|
|
196
|
+
task.save
|
|
197
|
+
|
|
198
|
+
TaskConnection.count.should eq(0)
|
|
199
|
+
Subtask.count.should eq(0)
|
|
200
|
+
Moderation.last.accept
|
|
201
|
+
Moderation.count.should eq(0)
|
|
202
|
+
Subtask.count.should eq(1)
|
|
203
|
+
|
|
204
|
+
subtask = Task.first.renamed_subtasks.first
|
|
205
|
+
subtask.title.should eq("Subtask 1")
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it "associates subtask 3 (update)" do
|
|
209
|
+
task = Task.create! :title => "Task 1"
|
|
210
|
+
Moderation.count.should eq(0)
|
|
211
|
+
|
|
212
|
+
task.renamed_subtasks.create! :title => "Subtask 1"
|
|
213
|
+
|
|
214
|
+
TaskConnection.count.should eq(0)
|
|
215
|
+
Subtask.count.should eq(0)
|
|
216
|
+
|
|
217
|
+
Moderation.last.accept
|
|
218
|
+
Moderation.count.should eq(0)
|
|
219
|
+
Subtask.count.should eq(1)
|
|
220
|
+
|
|
221
|
+
subtask = Task.first.renamed_subtasks.first
|
|
222
|
+
subtask.title.should eq("Subtask 1")
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
it "associates subtask 1 (create)" do
|
|
226
|
+
t = Task.new :title => "Task 1"
|
|
227
|
+
t.renamed_subtasks.build :title => "Subtask 1"
|
|
228
|
+
t.save
|
|
229
|
+
|
|
230
|
+
Subtask.count.should eq(0)
|
|
231
|
+
Task.first.renamed_subtasks.count.should eq(0)
|
|
232
|
+
Task.count.should eq(1)
|
|
233
|
+
|
|
234
|
+
Moderation.last.accept
|
|
235
|
+
|
|
236
|
+
Task.first.renamed_subtasks.count.should eq(1)
|
|
237
|
+
Task.first.renamed_subtasks.first.title.should eq("Subtask 1")
|
|
238
|
+
end
|
|
213
239
|
end
|
|
214
240
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
241
|
+
#
|
|
242
|
+
# has_moderated_association
|
|
243
|
+
# has_one
|
|
244
|
+
#
|
|
245
|
+
|
|
246
|
+
context "has_one association:" do
|
|
247
|
+
before do
|
|
248
|
+
Object.send(:remove_const, 'Task')
|
|
249
|
+
load 'task.rb'
|
|
250
|
+
Object.send(:remove_const, 'Subtask')
|
|
251
|
+
load 'subtask.rb'
|
|
252
|
+
Task.has_one :renamed_subtask, :class_name => "Subtask"
|
|
253
|
+
Task.has_moderated_association :renamed_subtask
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
it "creates and associates subtask (= new, task save)" do
|
|
257
|
+
task = Task.create! :title => "Task 1"
|
|
258
|
+
Moderation.count.should eq(0)
|
|
259
|
+
task.renamed_subtask = Subtask.new :title => "Subtask 1"
|
|
260
|
+
task.save
|
|
261
|
+
debugger
|
|
262
|
+
|
|
263
|
+
task = Task.first
|
|
264
|
+
task.renamed_subtask.should be_nil
|
|
265
|
+
Subtask.count.should eq(0)
|
|
266
|
+
|
|
267
|
+
Moderation.count.should eq(1)
|
|
268
|
+
Moderation.last.accept
|
|
269
|
+
Moderation.count.should eq(0)
|
|
270
|
+
|
|
271
|
+
subtask = Task.first.renamed_subtask
|
|
272
|
+
subtask.title.should eq("Subtask 1")
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
it "creates and associates subtask (= create, task save)" do
|
|
276
|
+
task = Task.create! :title => "Task 1"
|
|
277
|
+
Moderation.count.should eq(0)
|
|
278
|
+
task.renamed_subtask = Subtask.create! :title => "Subtask 1"
|
|
279
|
+
task.save
|
|
280
|
+
|
|
281
|
+
task = Task.first
|
|
282
|
+
task.renamed_subtask.should be_nil
|
|
283
|
+
|
|
284
|
+
Moderation.count.should eq(1)
|
|
285
|
+
Moderation.last.accept
|
|
286
|
+
Moderation.count.should eq(0)
|
|
287
|
+
|
|
288
|
+
subtask = Task.first.renamed_subtask
|
|
289
|
+
subtask.title.should eq("Subtask 1")
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it "set subtask to nil" do
|
|
293
|
+
task = Task.create! :title => "Task 1"
|
|
294
|
+
task.renamed_subtask = Subtask.new :title => "Subtask 1"
|
|
295
|
+
task.save
|
|
296
|
+
Moderation.last.accept
|
|
297
|
+
|
|
298
|
+
Moderation.count.should eq(0)
|
|
299
|
+
Task.first.renamed_subtask.should_not be_nil
|
|
300
|
+
|
|
301
|
+
Task.first.renamed_subtask = nil
|
|
302
|
+
Task.first.renamed_subtask.should_not be_nil
|
|
303
|
+
|
|
304
|
+
Moderation.last.accept
|
|
305
|
+
Task.first.renamed_subtask.should be_nil
|
|
306
|
+
end
|
|
229
307
|
end
|
|
230
308
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
309
|
+
#
|
|
310
|
+
# has_moderated_create
|
|
311
|
+
#
|
|
312
|
+
|
|
313
|
+
context "create moderation with association:" do
|
|
314
|
+
before do
|
|
315
|
+
Object.send(:remove_const, 'Task')
|
|
316
|
+
load 'task.rb'
|
|
317
|
+
Object.send(:remove_const, 'Subtask')
|
|
318
|
+
load 'subtask.rb'
|
|
319
|
+
# TODO: set very obscure options
|
|
320
|
+
Task.has_many :renamed_subtasks, :class_name => "Subtask"
|
|
321
|
+
Task.has_moderated_create :with_associations => [:renamed_subtasks]
|
|
322
|
+
end
|
|
235
323
|
|
|
236
|
-
|
|
324
|
+
it "moderates create" do
|
|
325
|
+
task = Task.create! :title => "Task 1"
|
|
326
|
+
Moderation.count.should eq(1)
|
|
327
|
+
Task.count.should eq(0)
|
|
328
|
+
|
|
329
|
+
Moderation.last.accept
|
|
330
|
+
Task.count.should eq(1)
|
|
331
|
+
Task.first.title.should eq("Task 1")
|
|
332
|
+
end
|
|
237
333
|
|
|
238
|
-
|
|
239
|
-
|
|
334
|
+
it "moderates assoc on create" do
|
|
335
|
+
task = Task.new :title => "Task 1"
|
|
336
|
+
task.renamed_subtasks.build :title => "Subtask 1"
|
|
337
|
+
task.save
|
|
338
|
+
Subtask.count.should eq(0)
|
|
339
|
+
Moderation.last.accept
|
|
340
|
+
|
|
341
|
+
Task.last.renamed_subtasks.count.should eq(1)
|
|
342
|
+
Task.last.renamed_subtasks.first.title.should eq("Subtask 1")
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
#
|
|
347
|
+
# has_moderated_destroy
|
|
348
|
+
#
|
|
349
|
+
|
|
350
|
+
context "destroy moderation:" do
|
|
351
|
+
before do
|
|
352
|
+
Object.send(:remove_const, 'Task')
|
|
353
|
+
load 'task.rb'
|
|
354
|
+
Object.send(:remove_const, 'Subtask')
|
|
355
|
+
load 'subtask.rb'
|
|
356
|
+
Task.has_moderated_destroy
|
|
357
|
+
end
|
|
240
358
|
|
|
241
|
-
|
|
242
|
-
|
|
359
|
+
it "moderates destroy" do
|
|
360
|
+
Task.create! :title => "Task 1"
|
|
361
|
+
Task.count.should eq(1)
|
|
362
|
+
Task.first.destroy
|
|
363
|
+
Task.count.should eq(1)
|
|
364
|
+
Moderation.last.accept
|
|
365
|
+
Task.count.should eq(0)
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
|
|
369
|
+
#
|
|
370
|
+
# has_moderated_attributes
|
|
371
|
+
#
|
|
372
|
+
|
|
373
|
+
context "moderates attributes:" do
|
|
374
|
+
before do
|
|
375
|
+
Object.send(:remove_const, 'Task')
|
|
376
|
+
load 'task.rb'
|
|
377
|
+
Object.send(:remove_const, 'Subtask')
|
|
378
|
+
load 'subtask.rb'
|
|
379
|
+
Task.has_moderated :title
|
|
380
|
+
end
|
|
243
381
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
382
|
+
it "moderates an attribute" do
|
|
383
|
+
Task.create! :title => "Task 1"
|
|
384
|
+
Task.first.title.should be_blank
|
|
385
|
+
Moderation.last.accept
|
|
386
|
+
Task.first.title.should eq("Task 1")
|
|
387
|
+
Task.first.update_attribute(:title, "Task 2")
|
|
388
|
+
Task.first.title.should eq("Task 1")
|
|
389
|
+
Moderation.last.accept
|
|
390
|
+
Task.first.title.should eq("Task 2")
|
|
391
|
+
end
|
|
247
392
|
end
|
|
248
393
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
394
|
+
#
|
|
395
|
+
# other features
|
|
396
|
+
#
|
|
397
|
+
|
|
398
|
+
context "common features:" do
|
|
399
|
+
before do
|
|
400
|
+
Object.send(:remove_const, 'Task')
|
|
401
|
+
load 'task.rb'
|
|
402
|
+
Object.send(:remove_const, 'Subtask')
|
|
403
|
+
load 'subtask.rb'
|
|
404
|
+
Task.has_moderated_create
|
|
405
|
+
Task.class_eval do
|
|
406
|
+
def get_moderation_attributes
|
|
407
|
+
{ :test => "ok" }
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
it "get_moderation_attributes can be overriden in model" do
|
|
412
|
+
Task.create! :title => "Task 1"
|
|
413
|
+
data = YAML::load(Moderation.last.data)[:create][:attributes]
|
|
414
|
+
data.should_not be_blank
|
|
415
|
+
data[:test].should_not be_blank
|
|
416
|
+
data[:test].should eq("ok")
|
|
417
|
+
data.keys.count.should eq(1)
|
|
418
|
+
end
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
context "hooks:" do
|
|
422
|
+
before do
|
|
423
|
+
Object.send(:remove_const, 'Task')
|
|
424
|
+
load 'task.rb'
|
|
425
|
+
Object.send(:remove_const, 'Subtask')
|
|
426
|
+
load 'subtask.rb'
|
|
427
|
+
Task.has_moderated :title
|
|
428
|
+
Task.moderation_creating do |moderation|
|
|
429
|
+
moderation.data = "Test!"
|
|
430
|
+
end
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
it "handles a creating hook properly" do
|
|
434
|
+
Task.create! :title => "Task 1"
|
|
435
|
+
Moderation.count.should eq(1)
|
|
436
|
+
Moderation.last.data.should eq("Test!")
|
|
437
|
+
end
|
|
271
438
|
end
|
|
272
439
|
end
|
|
@@ -24,4 +24,8 @@ RSpec.configure do |config|
|
|
|
24
24
|
# examples within a transaction, remove the following line or assign false
|
|
25
25
|
# instead of true.
|
|
26
26
|
config.use_transactional_fixtures = true
|
|
27
|
+
|
|
28
|
+
# Exclude broken tests
|
|
29
|
+
config.filter_run_excluding :broken => true
|
|
30
|
+
#config.filter_run :focus => true
|
|
27
31
|
end
|