decko 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/decko.gemspec +3 -3
- data/features/attach.feature +11 -7
- data/features/follow.feature +45 -44
- data/features/navbox.feature +1 -1
- data/features/notifications.feature +1 -1
- data/features/pointer_inputs.feature +7 -0
- data/features/reference.feature +5 -1
- data/features/step_definitions/email_steps.rb +4 -0
- data/features/step_definitions/wagn_steps.rb +6 -3
- data/features/step_definitions/web_steps.rb +1 -0
- data/features/support/delayed_job.rb +1 -0
- data/features/support/env.rb +5 -2
- data/features/toolbar.feature +13 -11
- data/lib/decko/application.rb +1 -0
- data/lib/decko/commands/cucumber_command.rb +2 -2
- data/lib/decko/commands/cucumber_command/parser.rb +8 -0
- data/lib/decko/commands/rspec_command.rb +3 -3
- data/lib/decko/config/environments/development.rb +3 -2
- data/lib/decko/config/environments/production.rb +4 -0
- data/lib/decko/config/environments/test.rb +2 -2
- data/lib/decko/config/initializers/sedate_parser.rb +7 -0
- data/lib/decko/engine.rb +1 -1
- data/lib/decko/generators/decko/templates/Gemfile +16 -22
- data/lib/decko/mods_spec_helper.rb +0 -1
- data/lib/decko/response.rb +18 -12
- data/lib/decko/tasks/alias.rb +31 -0
- data/lib/decko/tasks/decko.rake +16 -43
- data/lib/decko/tasks/decko/bootstrap.rake +65 -62
- data/lib/decko/tasks/test.rake +10 -3
- data/rails/controllers/card_controller.rb +16 -10
- data/rails/engine-routes.rb +4 -1
- data/spec/controllers/card_controller_spec.rb +77 -58
- data/spec/controllers/location_spec.rb +4 -4
- metadata +10 -9
- data/lib/decko/tasks/decko/migrate.rake +0 -77
data/lib/decko/tasks/test.rake
CHANGED
@@ -22,6 +22,15 @@ namespace :test do
|
|
22
22
|
ENV["GENERATE_FIXTURES"] = "true"
|
23
23
|
raise "must be test env" unless Rails.env == "test"
|
24
24
|
|
25
|
+
Rake::Task["test:repopulate_database"].invoke
|
26
|
+
|
27
|
+
puts ">>extracting to fixtures"
|
28
|
+
puts `rake test:extract_fixtures --trace`
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "seeds database and populates it with test data"
|
32
|
+
task repopulate_database: :environment do
|
33
|
+
raise "must be test env" unless Rails.env == "test"
|
25
34
|
Rake::Task["decko:reset_cache"]
|
26
35
|
|
27
36
|
puts "reseed test db"
|
@@ -29,11 +38,9 @@ namespace :test do
|
|
29
38
|
|
30
39
|
puts ">>populating test data"
|
31
40
|
puts `rake test:populate_template_database --trace`
|
32
|
-
|
33
|
-
puts ">>extracting to fixtures"
|
34
|
-
puts `rake test:extract_fixtures --trace`
|
35
41
|
end
|
36
42
|
|
43
|
+
|
37
44
|
desc "dump current db to test fixtures"
|
38
45
|
task extract_fixtures: :environment do
|
39
46
|
raise "must be test env" unless Rails.env == "test"
|
@@ -49,17 +49,24 @@ class CardController < ActionController::Base
|
|
49
49
|
|
50
50
|
#-------( FILTERS )
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
before_action :setup, except: [:asset]
|
53
|
+
before_action :authenticate, except: [:asset]
|
54
|
+
before_action :load_id, only: [:read]
|
55
|
+
before_action :load_card, except: [:asset]
|
56
|
+
before_action :refresh_card, only: [:create, :update, :delete]
|
57
57
|
|
58
58
|
def setup
|
59
59
|
request.format = :html unless params[:format] # is this used??
|
60
|
-
Card::
|
60
|
+
Card::Machine.refresh_script_and_style if Rails.env.development?
|
61
61
|
Card::Cache.renew
|
62
62
|
Card::Env.reset controller: self
|
63
|
+
# unprotect_card_params!
|
64
|
+
end
|
65
|
+
|
66
|
+
def unprotect_card_params!
|
67
|
+
# FIXME: always wear protection
|
68
|
+
return unless params[:card].is_a? ActionController::Parameters
|
69
|
+
params[:card].to_unsafe_h
|
63
70
|
end
|
64
71
|
|
65
72
|
def authenticate
|
@@ -71,7 +78,7 @@ class CardController < ActionController::Base
|
|
71
78
|
end
|
72
79
|
|
73
80
|
def load_card
|
74
|
-
@card = Card.
|
81
|
+
@card = Card.controller_fetch params
|
75
82
|
raise Card::Error::NotFound unless @card
|
76
83
|
@card.select_action_by_params params #
|
77
84
|
Card::Env[:main_name] = params[:main] || (card && card.name) || ""
|
@@ -107,8 +114,7 @@ class CardController < ActionController::Base
|
|
107
114
|
card.action = :read
|
108
115
|
card.content = card.last_draft_content if use_draft?
|
109
116
|
|
110
|
-
|
111
|
-
format = card.format formatname
|
117
|
+
format = format_from_params card
|
112
118
|
|
113
119
|
view ||= params[:view]
|
114
120
|
result = card.act do
|
@@ -116,7 +122,7 @@ class CardController < ActionController::Base
|
|
116
122
|
end
|
117
123
|
|
118
124
|
status = format.error_status || status
|
119
|
-
deliver
|
125
|
+
deliver format, result, status
|
120
126
|
end
|
121
127
|
|
122
128
|
def render_errors
|
data/rails/engine-routes.rb
CHANGED
@@ -41,7 +41,10 @@ Decko::Engine.routes.draw do
|
|
41
41
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
42
42
|
|
43
43
|
# standard non-RESTful
|
44
|
-
|
44
|
+
%w[create read update delete asset].each do |action|
|
45
|
+
get "(card)/#{action}(/:id(.:format))" => "card", action: action
|
46
|
+
end
|
47
|
+
|
45
48
|
match "(card)/create(/:id(.:format))" => "card#create", via: [:post, :patch]
|
46
49
|
match "(card)/update(/:id(.:format))" => "card#update", via: [:post, :put, :patch]
|
47
50
|
match "(card)/delete(/:id(.:format))" => "card#delete", via: :delete
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
describe CardController do
|
3
|
+
RSpec.describe CardController, type: :controller do
|
4
4
|
routes { Decko::Engine.routes }
|
5
5
|
|
6
6
|
include Capybara::DSL
|
@@ -63,11 +63,11 @@ describe CardController do
|
|
63
63
|
# maybe think about refactoring to use mocks etc. to reduce
|
64
64
|
# test dependencies.
|
65
65
|
it "creates cards" do
|
66
|
-
post :create, card: {
|
66
|
+
post :create, params: { card: {
|
67
67
|
name: "NewCardFoo",
|
68
68
|
type: "Basic",
|
69
69
|
content: "Bananas"
|
70
|
-
}
|
70
|
+
} }
|
71
71
|
assert_response 302
|
72
72
|
c = Card["NewCardFoo"]
|
73
73
|
expect(c.type_code).to eq(:basic)
|
@@ -75,18 +75,18 @@ describe CardController do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "handles permission denials" do
|
78
|
-
post :create, card: {
|
79
|
-
name: "LackPerms",
|
80
|
-
type: "Html"
|
81
|
-
}
|
78
|
+
post :create, params: { card: { name: "LackPerms", type: "Html" } }
|
82
79
|
assert_response 403
|
83
80
|
expect(Card["LackPerms"]).to be_nil
|
84
81
|
end
|
85
82
|
|
86
83
|
# no controller-specific handling. move test elsewhere
|
87
84
|
it "creates cardtype cards" do
|
88
|
-
|
89
|
-
|
85
|
+
post :create,
|
86
|
+
xhr: true,
|
87
|
+
params: { card: {
|
88
|
+
"content" => "test", type: "Cardtype", name: "Editor"
|
89
|
+
} }
|
90
90
|
expect(assigns["card"]).not_to be_nil
|
91
91
|
assert_response 200
|
92
92
|
c = Card["Editor"]
|
@@ -98,9 +98,9 @@ describe CardController do
|
|
98
98
|
@c = Card.create! name: "Problem", content: "boof"
|
99
99
|
@c.delete!
|
100
100
|
post :create,
|
101
|
-
card: {
|
101
|
+
params: { card: {
|
102
102
|
"name" => "Problem", "type" => "Phrase", "content" => "noof"
|
103
|
-
}
|
103
|
+
} }
|
104
104
|
assert_response 302
|
105
105
|
c = Card["Problem"]
|
106
106
|
expect(c.type_code).to eq(:phrase)
|
@@ -108,25 +108,26 @@ describe CardController do
|
|
108
108
|
|
109
109
|
context "multi-create" do
|
110
110
|
it "catches missing name error" do
|
111
|
-
post :create, "card" => {
|
111
|
+
post :create, params: { "card" => {
|
112
112
|
"name" => "",
|
113
113
|
"type" => "Fruit",
|
114
114
|
"subcards" => { "+text" => { "content" => "<p>abraid</p>" } }
|
115
|
-
}, "view" => "open"
|
115
|
+
}, "view" => "open" }
|
116
116
|
assert_response 422
|
117
117
|
expect(assigns["card"].errors[:name].first).to eq("can't be blank")
|
118
118
|
end
|
119
119
|
|
120
120
|
it "creates card with subcards" do
|
121
121
|
login_as "joe_admin"
|
122
|
-
|
122
|
+
$stop = true
|
123
|
+
post :create, xhr: true, params: { success: "REDIRECT: /", card: {
|
123
124
|
name: "Gala",
|
124
125
|
type: "Fruit",
|
125
126
|
subcards: {
|
126
127
|
"+kind" => { content: "apple" },
|
127
128
|
"+color" => { type: "Phrase", content: "red" }
|
128
129
|
}
|
129
|
-
}
|
130
|
+
} }
|
130
131
|
assert_response 200
|
131
132
|
expect(Card["Gala"]).not_to be_nil
|
132
133
|
expect(Card["Gala+kind"].content).to eq("apple")
|
@@ -135,14 +136,14 @@ describe CardController do
|
|
135
136
|
end
|
136
137
|
|
137
138
|
it "renders errors if create fails" do
|
138
|
-
post :create,
|
139
|
+
post :create, params: { card: { name: "Joe User" } }
|
139
140
|
assert_response 422
|
140
141
|
end
|
141
142
|
|
142
143
|
it "redirects to thanks if present" do
|
143
144
|
login_as "joe_admin"
|
144
|
-
|
145
|
-
card: { "name" => "Wombly" }
|
145
|
+
post :create, xhr: true, params: { success: "REDIRECT: /thank_you",
|
146
|
+
card: { "name" => "Wombly" } }
|
146
147
|
assert_response 200
|
147
148
|
json = JSON.parse response.body
|
148
149
|
expect(json["redirect"]).to match(/^http.*\/thank_you$/)
|
@@ -150,25 +151,25 @@ describe CardController do
|
|
150
151
|
|
151
152
|
it "redirects to card if thanks is blank" do
|
152
153
|
login_as "joe_admin"
|
153
|
-
post :create, success: "REDIRECT: _self",
|
154
|
-
|
154
|
+
post :create, params: { success: "REDIRECT: _self",
|
155
|
+
card: { name: "Joe+boop" } }
|
155
156
|
assert_redirected_to "/Joe+boop"
|
156
157
|
end
|
157
158
|
|
158
159
|
it "redirects to previous" do
|
159
160
|
# Fruits (from shared_data) are anon creatable but not readable
|
160
161
|
login_as :anonymous
|
161
|
-
post :create, { success: "REDIRECT: *previous",
|
162
|
-
|
163
|
-
|
162
|
+
post :create, params: { success: "REDIRECT: *previous",
|
163
|
+
"card" => { "type" => "Fruit", name: "papaya" } },
|
164
|
+
session: { history: ["/blam"] }
|
164
165
|
assert_redirected_to "/blam"
|
165
166
|
end
|
166
167
|
end
|
167
168
|
|
168
169
|
describe "#read" do
|
169
170
|
it "works for basic request" do
|
170
|
-
get :read, id: "Sample_Basic"
|
171
|
-
expect(response.body.match(/\<body[^>]*\>/im)
|
171
|
+
get :read, params: { id: "Sample_Basic" }
|
172
|
+
expect(response.body).to match(/\<body[^>]*\>/im)
|
172
173
|
# have_selector broke in commit 8d3bf2380eb8197410e962304c5e640fced684b9,
|
173
174
|
# presumably because of a gem (like capybara?)
|
174
175
|
# response.should have_selector('body')
|
@@ -178,17 +179,17 @@ describe CardController do
|
|
178
179
|
|
179
180
|
it "handles nonexistent card with create permission" do
|
180
181
|
login_as "joe_user"
|
181
|
-
get :read, id: "Sample_Fako"
|
182
|
+
get :read, params: { id: "Sample_Fako" }
|
182
183
|
assert_response :success
|
183
184
|
end
|
184
185
|
|
185
186
|
it "handles nonexistent card without create permissions" do
|
186
|
-
get :read, id: "Sample_Fako"
|
187
|
+
get :read, params: { id: "Sample_Fako" }
|
187
188
|
assert_response 404
|
188
189
|
end
|
189
190
|
|
190
191
|
it "handles nonexistent card ids" do
|
191
|
-
get :read, id: "~9999999"
|
192
|
+
get :read, params: { id: "~9999999" }
|
192
193
|
assert_response 404
|
193
194
|
end
|
194
195
|
|
@@ -196,9 +197,9 @@ describe CardController do
|
|
196
197
|
Card::Auth.as_bot do
|
197
198
|
Card.create! name: "Strawberry", type: "Fruit" # only admin can read
|
198
199
|
end
|
199
|
-
get :read, id: "Strawberry"
|
200
|
+
get :read, params: { id: "Strawberry" }
|
200
201
|
assert_response 403
|
201
|
-
get :read, id: "Strawberry", format: "txt"
|
202
|
+
get :read, params: { id: "Strawberry", format: "txt" }
|
202
203
|
assert_response 403
|
203
204
|
end
|
204
205
|
|
@@ -208,7 +209,7 @@ describe CardController do
|
|
208
209
|
end
|
209
210
|
|
210
211
|
it "works on index" do
|
211
|
-
get :read, view: "new"
|
212
|
+
get :read, params: { view: "new" }
|
212
213
|
expect(assigns["card"].name).to eq("")
|
213
214
|
assert_response :success, "response should succeed"
|
214
215
|
assert_equal Card::BasicID, assigns["card"].type_id,
|
@@ -216,20 +217,20 @@ describe CardController do
|
|
216
217
|
end
|
217
218
|
|
218
219
|
it "new with name" do
|
219
|
-
post :read, card: { name: "BananaBread" }, view: "new"
|
220
|
+
post :read, params: { card: { name: "BananaBread" }, view: "new" }
|
220
221
|
assert_response :success, "response should succeed"
|
221
222
|
assert_equal "BananaBread", assigns["card"].name,
|
222
223
|
"@card.name should == BananaBread"
|
223
224
|
end
|
224
225
|
|
225
226
|
it "new with existing name" do
|
226
|
-
get :read, card: { name: "A" }, view: "new"
|
227
|
+
get :read, params: { card: { name: "A" }, view: "new" }
|
227
228
|
# really?? how come this is ok?
|
228
229
|
assert_response :success, "response should succeed"
|
229
230
|
end
|
230
231
|
|
231
232
|
it "new with type_code" do
|
232
|
-
post :read, card: { type: "Date" }, view: "new"
|
233
|
+
post :read, params: { card: { type: "Date" }, view: "new" }
|
233
234
|
assert_response :success, "response should succeed"
|
234
235
|
assert_equal Card::DateID, assigns["card"].type_id,
|
235
236
|
"@card type should == Date"
|
@@ -237,12 +238,13 @@ describe CardController do
|
|
237
238
|
|
238
239
|
it "new should work for creatable nonviewable cardtype" do
|
239
240
|
login_as :anonymous
|
240
|
-
get :read, type: "Fruit", view: "new"
|
241
|
+
get :read, params: { type: "Fruit", view: "new" }
|
241
242
|
assert_response :success
|
242
243
|
end
|
243
244
|
|
244
245
|
it "uses card params name over id in new cards" do
|
245
|
-
get :read,
|
246
|
+
get :read, params: { id: "my_life",
|
247
|
+
card: { name: "My LIFE" }, view: "new" }
|
246
248
|
expect(assigns["card"].name).to eq("My LIFE")
|
247
249
|
end
|
248
250
|
end
|
@@ -254,14 +256,25 @@ describe CardController do
|
|
254
256
|
end
|
255
257
|
|
256
258
|
it "creates missing machine output file" do
|
257
|
-
args = { id: @all_style.machine_output_card.name,
|
259
|
+
args = { params: { id: @all_style.machine_output_card.name,
|
258
260
|
format: "css",
|
259
|
-
explicit_file: true }
|
261
|
+
explicit_file: true } }
|
260
262
|
get :read, args
|
261
263
|
# output_card = Card[:all, :style, :machine_output]
|
262
264
|
expect(response).to redirect_to(@all_style.machine_output_url)
|
263
265
|
get :read, args
|
264
266
|
expect(response.status).to eq(200)
|
267
|
+
expect(response.content_type).to eq("text/css")
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
context "js" do
|
272
|
+
let(:all_js) { Card[:all, :script] }
|
273
|
+
|
274
|
+
it "has correct MIME type" do
|
275
|
+
get :read, params: { id: all_js.machine_output_card.name, format: "js" }
|
276
|
+
expect(response.status).to eq 200
|
277
|
+
expect(response.content_type).to eq "text/javascript"
|
265
278
|
end
|
266
279
|
end
|
267
280
|
|
@@ -275,17 +288,17 @@ describe CardController do
|
|
275
288
|
end
|
276
289
|
|
277
290
|
it "handles image with no read permission" do
|
278
|
-
get :read, id: "mao2"
|
291
|
+
get :read, params: { id: "mao2" }
|
279
292
|
assert_response 403, "denies html card view"
|
280
|
-
get :read, id: "mao2", format: "jpg"
|
293
|
+
get :read, params: { id: "mao2", format: "jpg" }
|
281
294
|
assert_response 403, "denies simple file view"
|
282
295
|
end
|
283
296
|
|
284
297
|
it "handles image with read permission" do
|
285
298
|
login_as "joe_admin"
|
286
|
-
get :read, id: "mao2"
|
299
|
+
get :read, params: { id: "mao2" }
|
287
300
|
assert_response 200
|
288
|
-
get :read, id: "mao2", format: "jpg"
|
301
|
+
get :read, params: { id: "mao2", format: "jpg" }
|
289
302
|
assert_response 200
|
290
303
|
end
|
291
304
|
end
|
@@ -305,8 +318,7 @@ describe CardController do
|
|
305
318
|
end
|
306
319
|
|
307
320
|
it "denies access to other directories" do
|
308
|
-
|
309
|
-
get :asset, args
|
321
|
+
get :asset, params: { filename: "/../../Gemfile" }
|
310
322
|
expect(response.status).to eq(404)
|
311
323
|
end
|
312
324
|
end
|
@@ -319,8 +331,8 @@ describe CardController do
|
|
319
331
|
|
320
332
|
describe "#update" do
|
321
333
|
it "works" do
|
322
|
-
|
323
|
-
card: { content: "brand new content" }
|
334
|
+
post :update, xhr: true, params: { id: "~#{@simple_card.id}",
|
335
|
+
card: { content: "brand new content" } }
|
324
336
|
assert_response :success, "edited card"
|
325
337
|
assert_equal "brand new content", Card["Sample Basic"].content,
|
326
338
|
"content was updated"
|
@@ -328,17 +340,22 @@ describe CardController do
|
|
328
340
|
|
329
341
|
it "rename without update references should work" do
|
330
342
|
f = Card.create! type: "Cardtype", name: "Apple"
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
343
|
+
post :update, xhr: true,
|
344
|
+
params: {
|
345
|
+
id: "~#{f.id}",
|
346
|
+
card: { name: "Newt", update_referers: "false" }
|
347
|
+
}
|
335
348
|
expect(assigns["card"].errors.empty?).not_to be_nil
|
336
349
|
assert_response :success
|
337
350
|
expect(Card["Newt"]).not_to be_nil
|
338
351
|
end
|
339
352
|
|
340
353
|
it "update type_code" do
|
341
|
-
|
354
|
+
post :update, xhr: true,
|
355
|
+
params: {
|
356
|
+
id: "~#{@simple_card.id}",
|
357
|
+
card: { type: "Date" }
|
358
|
+
}
|
342
359
|
assert_response :success, "changed card type"
|
343
360
|
expect(Card["Sample Basic"].type_code).to eq(:date)
|
344
361
|
end
|
@@ -347,7 +364,7 @@ describe CardController do
|
|
347
364
|
describe "delete" do
|
348
365
|
it "works" do
|
349
366
|
c = Card.create(name: "Boo", content: "booya")
|
350
|
-
post :delete, id: "~#{c.id}"
|
367
|
+
post :delete, params: { id: "~#{c.id}" }
|
351
368
|
assert_response :redirect
|
352
369
|
expect(Card["Boo"]).to eq(nil)
|
353
370
|
end
|
@@ -360,14 +377,14 @@ describe CardController do
|
|
360
377
|
t2 = Card.create! name: "Testable1+bandana", content: "world"
|
361
378
|
end
|
362
379
|
|
363
|
-
get :read, id: t1.key
|
364
|
-
get :read, id: t2.key
|
380
|
+
get :read, params: { id: t1.key }
|
381
|
+
get :read, params: { id: t2.key }
|
365
382
|
|
366
|
-
post :delete, id: "~" + t2.id.to_s
|
383
|
+
post :delete, params: { id: "~" + t2.id.to_s }
|
367
384
|
assert_nil Card[t2.name]
|
368
385
|
assert_redirected_to "/#{t1.name}"
|
369
386
|
|
370
|
-
post :delete, id: "~" + t1.id.to_s
|
387
|
+
post :delete, params: { id: "~" + t1.id.to_s }
|
371
388
|
assert_redirected_to "/"
|
372
389
|
assert_nil Card[t1.name]
|
373
390
|
end
|
@@ -378,8 +395,10 @@ describe CardController do
|
|
378
395
|
Card.create name: "basicname+*self+*comment",
|
379
396
|
content: "[[Anyone Signed In]]"
|
380
397
|
end
|
381
|
-
post :update,
|
382
|
-
|
398
|
+
post :update, params: {
|
399
|
+
id: "basicname",
|
400
|
+
card: { comment: " and more\n \nsome lines\n\n" }
|
401
|
+
}
|
383
402
|
cont = Card["basicname"].content
|
384
403
|
expect(cont).to match(/basiccontent/)
|
385
404
|
expect(cont).to match(/some lines/)
|