abstracted 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -3
- data/Gemfile.lock +12 -10
- data/app/assets/javascripts/abstract_resources.js +0 -1
- data/app/assets/javascripts/abstracted/app.fab_delete.coffee +3 -26
- data/app/assets/javascripts/abstracted/app.materialize.coffee +15 -1
- data/app/assets/javascripts/abstracted/app.page_scrolling.coffee +143 -0
- data/app/assets/javascripts/abstracted/app.resource_form.coffee +0 -7
- data/app/assets/javascripts/abstracted/app.resources_list.coffee +7 -4
- data/app/assets/javascripts/abstracted/app.shared.coffee +3 -0
- data/app/assets/javascripts/init.js.coffee +58 -18
- data/app/assets/javascripts/triggers.coffee +9 -21
- data/app/assets/stylesheets/abstract_resources.css +1 -0
- data/app/assets/stylesheets/balloon.min.css +1 -0
- data/app/controllers/abstract_resources_controller.rb +22 -20
- data/app/helpers/abstract_resources_helper.rb +2 -2
- data/app/models/abstract_resource.rb +29 -28
- data/app/views/abstract_resources/index.html.haml +32 -14
- data/app/views/abstract_resources/show.html.haml +3 -2
- data/lib/abstracted/version.rb +1 -1
- data/lib/exceptions.rb +2 -0
- data/spec/controllers/abstract_resources_controller_spec.rb +316 -176
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/test.log +8801 -0
- data/spec/policies/abstract_resources_policy.rb +83 -0
- data/spec/rails_helper.rb +92 -1
- data/spec/spec_helper.rb +2 -0
- metadata +6 -3
- data/app/assets/javascripts/pagescrolling.js.coffee +0 -93
@@ -9,26 +9,14 @@ $(App).on 'app:modal:open', ->
|
|
9
9
|
App.trigger('app:pageload')
|
10
10
|
|
11
11
|
$(App).on 'app:pageload', ->
|
12
|
-
|
13
|
-
|
14
|
-
sweet = new App.SweetAlert()
|
15
|
-
sweet.prepare()
|
12
|
+
App.page.prepare()
|
13
|
+
App.sweet.prepare()
|
16
14
|
if $('table.resources_table')
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
fab = new App.fabDelete()
|
22
|
-
fab.prepare()
|
15
|
+
App.resourceslist.prepare()
|
16
|
+
App.ps.scrollTable('table.resources_table')
|
17
|
+
App.resourceform.prepare()
|
18
|
+
App.fab.prepare()
|
23
19
|
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# @pageOnChange = () ->
|
29
|
-
# console.log 'page changed '
|
30
|
-
# pageOnLoad()
|
31
|
-
#
|
32
|
-
# call the App.pageload
|
33
|
-
$(document).on 'page:change', ->
|
34
|
-
App.pageload()
|
20
|
+
# $(App).on 'app:pageunload', ->
|
21
|
+
# if App.ps && App.ps.scrollTimeout
|
22
|
+
# clearTimeout App.ps.scrollTimeout
|
@@ -0,0 +1 @@
|
|
1
|
+
[data-balloon]{position:relative}[data-balloon]::before{opacity:0;pointer-events:none;transition:all .18s ease-out;background:rgba(17,17,17,0.9);border-radius:4px;color:#fff;content:attr(data-balloon);font-size:12px;padding:.5em 1em;position:absolute;white-space:nowrap;z-index:10}[data-balloon]::after{background:no-repeat url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="36px" height="12px"><path fill="rgba(17,17,17,0.9)" transform="rotate(0)" d="M2.658,0.000 C-13.615,0.000 50.938,0.000 34.662,0.000 C28.662,0.000 23.035,12.002 18.660,12.002 C14.285,12.002 8.594,0.000 2.658,0.000 Z"/></svg>');background-size:100% auto;width:18px;height:6px;opacity:0;pointer-events:none;transition:all .18s ease-out;content:'';position:absolute;z-index:10}[data-balloon]:hover::before,[data-balloon]:hover::after{opacity:1;pointer-events:auto}[data-balloon][data-balloon-pos="up"]::before{bottom:100%;left:50%;margin-bottom:11px;transform:translate3d(-50%, 10px, 0);transform-origin:top}[data-balloon][data-balloon-pos="up"]::after{bottom:100%;left:50%;margin-bottom:5px;transform:translate3d(-50%, 10px, 0);transform-origin:top}[data-balloon][data-balloon-pos="up"]:hover::before{transform:translate3d(-50%, 0, 0)}[data-balloon][data-balloon-pos="up"]:hover::after{transform:translate3d(-50%, 0, 0)}[data-balloon][data-balloon-pos='down']::before{left:50%;margin-top:11px;top:100%;transform:translate3d(-50%, -10px, 0)}[data-balloon][data-balloon-pos='down']::after{background:no-repeat url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="36px" height="12px"><path fill="rgba(17,17,17,0.9)" transform="rotate(180 18 6)" d="M2.658,0.000 C-13.615,0.000 50.938,0.000 34.662,0.000 C28.662,0.000 23.035,12.002 18.660,12.002 C14.285,12.002 8.594,0.000 2.658,0.000 Z"/></svg>');background-size:100% auto;width:18px;height:6px;left:50%;margin-top:5px;top:100%;transform:translate3d(-50%, -10px, 0)}[data-balloon][data-balloon-pos='down']:hover::before{transform:translate3d(-50%, 0, 0)}[data-balloon][data-balloon-pos='down']:hover::after{transform:translate3d(-50%, 0, 0)}[data-balloon][data-balloon-pos='left']::before{margin-right:11px;right:100%;top:50%;transform:translate3d(10px, -50%, 0)}[data-balloon][data-balloon-pos='left']::after{background:no-repeat url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12px" height="36px"><path fill="rgba(17,17,17,0.9)" transform="rotate(-90 18 18)" d="M2.658,0.000 C-13.615,0.000 50.938,0.000 34.662,0.000 C28.662,0.000 23.035,12.002 18.660,12.002 C14.285,12.002 8.594,0.000 2.658,0.000 Z"/></svg>');background-size:100% auto;width:6px;height:18px;margin-right:5px;right:100%;top:50%;transform:translate3d(10px, -50%, 0)}[data-balloon][data-balloon-pos='left']:hover::before{transform:translate3d(0, -50%, 0)}[data-balloon][data-balloon-pos='left']:hover::after{transform:translate3d(0, -50%, 0)}[data-balloon][data-balloon-pos='right']::before{left:100%;margin-left:11px;top:50%;transform:translate3d(-10px, -50%, 0)}[data-balloon][data-balloon-pos='right']::after{background:no-repeat url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12px" height="36px"><path fill="rgba(17,17,17,0.9)" transform="rotate(90 6 6)" d="M2.658,0.000 C-13.615,0.000 50.938,0.000 34.662,0.000 C28.662,0.000 23.035,12.002 18.660,12.002 C14.285,12.002 8.594,0.000 2.658,0.000 Z"/></svg>');background-size:100% auto;width:6px;height:18px;left:100%;margin-left:5px;top:50%;transform:translate3d(-10px, -50%, 0)}[data-balloon][data-balloon-pos='right']:hover::before{transform:translate3d(0, -50%, 0)}[data-balloon][data-balloon-pos='right']:hover::after{transform:translate3d(0, -50%, 0)}[data-balloon][data-balloon-length='small']::before{white-space:normal;width:80px}[data-balloon][data-balloon-length='medium']::before{white-space:normal;width:150px}[data-balloon][data-balloon-length='large']::before{white-space:normal;width:260px}[data-balloon][data-balloon-length='xlarge']::before{white-space:normal;width:380px}@media screen and (max-width: 768px){[data-balloon][data-balloon-length='xlarge']::before{white-space:normal;width:90vw}}[data-balloon][data-balloon-length='fit']::before{white-space:normal;width:100%}
|
@@ -104,11 +104,9 @@ class AbstractResourcesController < ApplicationController
|
|
104
104
|
#
|
105
105
|
# build an array of the resource - particular to <SELECT>
|
106
106
|
def set_parents
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
@parents = resource_class.arraying({ order: 'name'}, resource.possible_parents)
|
111
|
-
end
|
107
|
+
@parents = []
|
108
|
+
return @parents unless resource_class.respond_to? :roots #( 'arraying') && resource? )
|
109
|
+
@parents = resource_class.arraying({ order: 'name'}, resource.possible_parents)
|
112
110
|
rescue Exception => e
|
113
111
|
scoop_from_error e
|
114
112
|
end
|
@@ -315,13 +313,14 @@ class AbstractResourcesController < ApplicationController
|
|
315
313
|
#
|
316
314
|
# returns the url for the resource - like /users/1
|
317
315
|
def resource_url options={}
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
when '
|
322
|
-
else
|
323
|
-
|
324
|
-
|
316
|
+
r=request.path
|
317
|
+
id=params[:id]
|
318
|
+
options = case params[:action]
|
319
|
+
when 'create','update','delete','destroy'; ""
|
320
|
+
else resource_options(options)
|
321
|
+
end
|
322
|
+
return "%s%s" % [r,options] if r.match "#{resource.class.to_s.tableize}\/#{id}$"
|
323
|
+
"%s%s" % [ r.split("/#{params[:action]}")[0], options]
|
325
324
|
rescue Exception => e
|
326
325
|
scoop_from_error e
|
327
326
|
end
|
@@ -330,11 +329,13 @@ class AbstractResourcesController < ApplicationController
|
|
330
329
|
#
|
331
330
|
# returns the url for the resources - /employees or /employees/1/events
|
332
331
|
def resources_url options={}
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
332
|
+
r=request.path
|
333
|
+
options = case params[:action]
|
334
|
+
when 'create','update','delete','destroy'; ""
|
335
|
+
else resource_options(options)
|
336
|
+
end
|
337
|
+
return "%s%s" % [r,options] if r.match "#{resource.class.to_s.tableize}$"
|
338
|
+
"%s%s%s" % [ r.split( resource.class.to_s.tableize)[0],resource.class.to_s.tableize, options]
|
338
339
|
rescue Exception => e
|
339
340
|
scoop_from_error e
|
340
341
|
end
|
@@ -342,7 +343,8 @@ class AbstractResourcesController < ApplicationController
|
|
342
343
|
#
|
343
344
|
# parent_url returns the parent url - /employees/1
|
344
345
|
def parent_url options={}
|
345
|
-
parent? ? (
|
346
|
+
parent? ? url_for(@parent) : ""
|
347
|
+
# parent? ? ( "/%s/%s" % [ @parent.class.table_name, @parent.id ] ) : ""
|
346
348
|
rescue Exception => e
|
347
349
|
scoop_from_error e
|
348
350
|
end
|
@@ -405,7 +407,7 @@ class AbstractResourcesController < ApplicationController
|
|
405
407
|
end
|
406
408
|
|
407
409
|
def resource_options options
|
408
|
-
options.merge! params.except( "id", "controller", "action" )
|
410
|
+
options.merge! params.except( "id", "controller", "action", "utf8", "_method", "authenticity_token" )
|
409
411
|
options = (options.empty? ? "" : "?" + options.collect{ |k,v| "#{k}=#{v}" }.join("&"))
|
410
412
|
end
|
411
413
|
|
@@ -558,7 +560,7 @@ class AbstractResourcesController < ApplicationController
|
|
558
560
|
#
|
559
561
|
|
560
562
|
def scoop_from_error e
|
561
|
-
raise e if Rails.env
|
563
|
+
raise e if %w{ test development }.include? Rails.env
|
562
564
|
logger.debug "AbstractResourcesController##{params[:action]}: #{e.class}"
|
563
565
|
a_url = root_path
|
564
566
|
|
@@ -199,8 +199,8 @@ module AbstractResourcesHelper
|
|
199
199
|
|
200
200
|
# return a link to delete a row
|
201
201
|
def show_resource_delete_icon item, url, lbl='name'
|
202
|
-
link_to item, class: 'delete_link', data: { url: url, name: "#{item.send lbl }", id: "#{item.id}", remove: "#tr-#{item.class.to_s}-#{item.id}" } do
|
203
|
-
content_tag :i, 'delete', class: 'material-icons small'
|
202
|
+
link_to item, class: 'delete_link', data: { balloon: t("balloons.delete" ), balloon_pos: "left", url: url, name: "#{item.send lbl }", id: "#{item.id}", remove: "#tr-#{item.class.to_s}-#{item.id}" } do
|
203
|
+
content_tag :i, 'delete', class: 'material-icons small'
|
204
204
|
end
|
205
205
|
# = link_to account, class: 'delete_link', data: { url: '/admin/accounts', name: "#{account.name}", id: "#{account.id}", remove: "#tr-#{account.id}" } do
|
206
206
|
# %i.material-icons.small{ title: "#{t('.delete')}"} delete
|
@@ -35,21 +35,24 @@ class AbstractResource < ActiveRecord::Base
|
|
35
35
|
lot.where id: population
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
38
|
+
# depreciated ------------ 12/3/2016
|
39
|
+
#
|
40
|
+
# ancestry related methods - find them on AncestryAbstractResource
|
41
|
+
# def self.arrange_array(options={}, hash=nil)
|
42
|
+
# hash ||= arrange(options)
|
43
|
+
#
|
44
|
+
# arr = []
|
45
|
+
# hash.each do |node, children|
|
46
|
+
# arr << node
|
47
|
+
# arr += arrange_array(options, children) unless children.nil?
|
48
|
+
# end
|
49
|
+
# arr
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# def possible_parents
|
53
|
+
# prtns = self.arrange_array(:order => 'name')
|
54
|
+
# return new_record? ? prtns : prtns - subtree
|
55
|
+
# end
|
53
56
|
|
54
57
|
def resource_name
|
55
58
|
self.class.to_s.underscore.pluralize
|
@@ -57,7 +60,7 @@ class AbstractResource < ActiveRecord::Base
|
|
57
60
|
|
58
61
|
#
|
59
62
|
# include Exceptions
|
60
|
-
include PrintEngine
|
63
|
+
include PrintEngine unless Rails.env=='test'
|
61
64
|
#
|
62
65
|
#
|
63
66
|
#
|
@@ -67,16 +70,9 @@ class AbstractResource < ActiveRecord::Base
|
|
67
70
|
# end
|
68
71
|
#
|
69
72
|
# # implement on relevant models
|
70
|
-
def
|
71
|
-
'
|
72
|
-
|
73
|
-
|
74
|
-
def self.default_list_template
|
75
|
-
'list.html.haml'
|
76
|
-
end
|
77
|
-
|
78
|
-
def self.default_label_template
|
79
|
-
'label.html.haml'
|
73
|
+
def find_template paper="A4"
|
74
|
+
raise 'you have to implement "def find_template(paper)" on your Model'
|
75
|
+
# 'label.html.haml'
|
80
76
|
end
|
81
77
|
#
|
82
78
|
# def print_label options={}
|
@@ -94,13 +90,14 @@ class AbstractResource < ActiveRecord::Base
|
|
94
90
|
def print_record(options={})
|
95
91
|
params = {}
|
96
92
|
params[:context] = options[:context]
|
93
|
+
template = options[:template]
|
97
94
|
options = options[:params]
|
98
95
|
params[:print_job] = {}
|
99
96
|
params[:print_job][:download] = options[:download] || false
|
100
97
|
params[:print_job][:print_driver] = options[:print_driver] || :pdf
|
101
98
|
params[:print_job][:print_format] = options[:print_format] || 'sheet'
|
102
99
|
params[:print_job][:paper] = options[:paper] || "A4"
|
103
|
-
params[:print_job][:view_template_path] =
|
100
|
+
params[:print_job][:view_template_path] = template || self.find_template( options[:paper] )
|
104
101
|
params[:printer_name] = options[:printer_name]
|
105
102
|
params[:user] = options[:user]
|
106
103
|
pj = self.class.print [self], params
|
@@ -108,12 +105,16 @@ class AbstractResource < ActiveRecord::Base
|
|
108
105
|
#
|
109
106
|
def self.print_list(options={})
|
110
107
|
params = {}
|
108
|
+
params[:context] = options[:context]
|
109
|
+
template = options[:template]
|
110
|
+
options = options[:params]
|
111
111
|
params[:print_job] = {}
|
112
112
|
params[:print_job][:download] = options[:download] || false
|
113
113
|
params[:print_job][:print_driver] = options[:print_driver] || :pdf
|
114
114
|
params[:print_job][:print_format] = options[:print_format] || 'list'
|
115
115
|
params[:print_job][:paper] = options[:paper] || "A4"
|
116
|
-
params[:print_job][:view_template_path] =
|
116
|
+
params[:print_job][:view_template_path] = template || self.find_template( options[:paper] )
|
117
|
+
|
117
118
|
params[:printer_name] = options[:printer_name]
|
118
119
|
params[:user] = options[:user]
|
119
120
|
self.print options[:resources], params
|
@@ -3,26 +3,44 @@
|
|
3
3
|
-# .col.s12
|
4
4
|
-# %h3= yield :title
|
5
5
|
|
6
|
-
.row
|
7
|
-
.col.s12
|
8
|
-
%form.form-inline{ action: resources_url( resources, controller: params[:controller]), method: "get"}
|
9
|
-
|
10
|
-
%label
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
6
|
+
.row{ style: "margin-top: 20px"}
|
7
|
+
.col.s12.m12.l12
|
8
|
+
%form#list-search-form.form-inline{ action: resources_url( resources, controller: params[:controller]), method: "get"}
|
9
|
+
- if resources.respond_to? :total_count
|
10
|
+
%label
|
11
|
+
%span.blue-grey-text{style: "margin-top: 6px"}
|
12
|
+
= t("#{resources_name}.posts", size: resources.total_count)
|
13
|
+
%br
|
14
|
+
%input.search-list.form-control{ style: "width: 75%", type: "text", id: "q", name: "q", placeholder: t("#{params[:controller]}.search_placeholder"), value: "#{params[:q] || ''}" }
|
15
|
+
%a.search-list.btn.btn-primary{ type: "submit"}= t('search_button_text')
|
16
|
+
|
17
|
+
-# .form-group
|
18
|
+
-# -# %label{ for: "q" }
|
19
|
+
-# %input.search-list.form-control{ type: "text", id: "q", name: "q", placeholder: t("#{params[:controller]}.search_placeholder"), value: "#{params[:q] || ''}" }
|
20
|
+
-# .collection{ style: "border: 0px"}
|
21
|
+
-# %a.search-list.btn.btn-primary{ type: "submit"}= t('search_button_text')
|
22
|
+
-# - if resources.respond_to? :total_count
|
23
|
+
-# %span.blue-grey-text{style: "margin-top: 6px"}
|
24
|
+
-# = t("#{resources_name}.posts", size: resources.total_count)
|
19
25
|
|
20
26
|
.row
|
21
27
|
.col.s12
|
22
28
|
|
23
29
|
.row
|
24
30
|
.col.s12
|
25
|
-
%table.bordered.responsive-table.striped.hoverable.page.resources_table
|
31
|
+
%table.bordered.responsive-table.striped.hoverable.page.resources_table{ id: "#{resource_name}_table_list"}
|
26
32
|
= render partial: resources_name
|
27
33
|
|
28
34
|
= build_fab_button build_fab_options( resource, fab_button_options.merge!( action: params[:action] ))
|
35
|
+
|
36
|
+
:coffeescript
|
37
|
+
|
38
|
+
$ ->
|
39
|
+
# console.log 'calling scrollTable ' + $('table.resources_table')[0].id
|
40
|
+
# if App.ps
|
41
|
+
# if App.ps.scrollTimeout
|
42
|
+
# clearTimeout App.ps.scrollTimeout
|
43
|
+
# if App.ps.lastPage > App.ps.nextPage
|
44
|
+
# App.shared.callToast 'Der er mere end én side resultater - scroll ned for at se flere!'
|
45
|
+
#
|
46
|
+
# App.ps.scrollTable('table.resources_table')
|
@@ -3,5 +3,6 @@
|
|
3
3
|
%h3= render partial: 'title'
|
4
4
|
- @disabled = true
|
5
5
|
= render 'form'
|
6
|
-
|
7
|
-
=
|
6
|
+
- unless params[:format] == 'js'
|
7
|
+
= build_fab_button build_fab_options( resource, fab_button_options.merge!( action: params[:action] ))
|
8
|
+
= render partial: 'show'
|
data/lib/abstracted/version.rb
CHANGED
data/lib/exceptions.rb
CHANGED
@@ -18,27 +18,166 @@ require 'rails_helper'
|
|
18
18
|
# is no simpler way to get a handle on the object needed for the example.
|
19
19
|
# Message expectations are only used when there is no simpler way to specify
|
20
20
|
# that an instance is receiving a specific message.
|
21
|
-
RSpec.describe "nested requests", :type => :request do
|
21
|
+
# RSpec.describe "nested requests", :type => :request do
|
22
|
+
#
|
23
|
+
# describe "GET #index" do
|
24
|
+
# it "gets all posts" do
|
25
|
+
# get "/posts"
|
26
|
+
# expect(assigns(:posts)).not_to eq([])
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# it "gets all posts to a user" do
|
30
|
+
# user = User.create(login: 'fisk')
|
31
|
+
# post = Post.create(user: user, title: 'fisk')
|
32
|
+
# get user_posts_path(user_id: user.id)
|
33
|
+
# expect(@controller.parent?).to eq true
|
34
|
+
# expect(@controller.resources_url).to eq "/users/1/posts"
|
35
|
+
# expect(@controller.resources.first).to eq (post)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# end
|
41
|
+
RSpec.describe "testing resource_url - for nested requests", type: :request do
|
42
|
+
describe "nested other ACTION" do
|
43
|
+
it "/users/1/print" do
|
44
|
+
user = User.create! id: 1, login: "test"
|
45
|
+
get "/users/1/print"
|
46
|
+
expect(@controller.resource_url).to eq("/users/1?ids=[\"1\"]")
|
47
|
+
end
|
48
|
+
it "/users/1/posts/1print" do
|
49
|
+
user = User.create! id: 1, login: "test"
|
50
|
+
post = Post.create! id: 1, user_id: user.id, title: "test"
|
51
|
+
get "/users/1/posts/1/print"
|
52
|
+
expect(@controller.resource_url).to eq("/users/1/posts/1?user_id=1&ids=[\"1\"]")
|
53
|
+
end
|
54
|
+
it "/admin/users/1/posts/1/print" do
|
55
|
+
user = User.create! id: 1, login: "test"
|
56
|
+
post = Post.create! id: 1, user_id: user.id, title: "test"
|
57
|
+
get "/admin/users/1/posts/1/print"
|
58
|
+
expect(@controller.resource_url).to eq("/admin/users/1/posts/1?user_id=1&ids=[\"1\"]")
|
59
|
+
end
|
60
|
+
it "/admin/users/1/edit" do
|
61
|
+
user = User.create! id: 1, login: "test"
|
62
|
+
get "/admin/users/1/edit"
|
63
|
+
expect(@controller.resource_url).to eq("/admin/users/1")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
describe "nested EDIT" do
|
67
|
+
it "/users/1/posts/1/edit" do
|
68
|
+
user = User.create! id: 1, login: "test"
|
69
|
+
post = Post.create! id: 1, user_id: user.id, title: "test"
|
70
|
+
get "/users/1/posts/1/edit"
|
71
|
+
expect(@controller.resource_url).to eq("/users/1/posts/1?user_id=1")
|
72
|
+
end
|
73
|
+
it "/admin/users/1/edit" do
|
74
|
+
user = User.create! id: 1, login: "test"
|
75
|
+
get "/admin/users/1/edit"
|
76
|
+
expect(@controller.resource_url).to eq("/admin/users/1")
|
77
|
+
end
|
78
|
+
it "/users/1/edit" do
|
79
|
+
user = User.create! id: 1, login: "test"
|
80
|
+
get "/users/1/edit"
|
81
|
+
expect(@controller.resource_url).to eq("/users/1")
|
82
|
+
end
|
83
|
+
it "/admin/users/1/edit?q=mx" do
|
84
|
+
user = User.create! id: 1, login: "test"
|
85
|
+
get "/admin/users/1/edit?q=mx"
|
86
|
+
expect(@controller.resource_url).to eq("/admin/users/1?q=mx")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
describe "nested GET" do
|
90
|
+
it "/users/1/posts/1" do
|
91
|
+
user = User.create! id: 1, login: "test"
|
92
|
+
post = Post.create! id: 1, user_id: user.id, title: "test"
|
93
|
+
get "/users/1/posts/1"
|
94
|
+
expect(@controller.resource_url).to eq("/users/1/posts/1?user_id=1")
|
95
|
+
end
|
96
|
+
it "/admin/users/1" do
|
97
|
+
user = User.create! id: 1, login: "test"
|
98
|
+
get "/admin/users/1"
|
99
|
+
expect(@controller.resource_url).to eq("/admin/users/1")
|
100
|
+
end
|
101
|
+
it "/users/1" do
|
102
|
+
user = User.create! id: 1, login: "test"
|
103
|
+
get "/users/1"
|
104
|
+
expect(@controller.resource_url).to eq("/users/1")
|
105
|
+
end
|
106
|
+
it "/admin/users/1?q=mx" do
|
107
|
+
user = User.create! id: 1, login: "test"
|
108
|
+
get "/admin/users/1?q=mx"
|
109
|
+
expect(@controller.resource_url).to eq("/admin/users/1?q=mx")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
22
113
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
114
|
+
RSpec.describe "testing resources_url - for nested requests", type: :request do
|
115
|
+
describe "nested EDIT" do
|
116
|
+
it "/users/1/posts/1/edit" do
|
117
|
+
user = User.create! id: 1, login: "test"
|
118
|
+
post = Post.create! id: 1, user_id: user.id, title: "test"
|
119
|
+
get "/users/1/posts/1/edit"
|
120
|
+
expect(@controller.resources_url).to eq("/users/1/posts?user_id=1")
|
121
|
+
|
122
|
+
end
|
123
|
+
it "/admin/users/1/edit" do
|
124
|
+
user = User.create! id: 1, login: "test"
|
125
|
+
get "/admin/users/1/edit"
|
126
|
+
expect(@controller.resources_url).to eq("/admin/users")
|
27
127
|
end
|
128
|
+
it "/users/1/edit" do
|
129
|
+
user = User.create! id: 1, login: "test"
|
130
|
+
get "/users/1/edit"
|
131
|
+
expect(@controller.resources_url).to eq("/users")
|
132
|
+
end
|
133
|
+
it "/admin/users/1/edit?q=mx" do
|
134
|
+
user = User.create! id: 1, login: "test"
|
135
|
+
get "/admin/users/1/edit?q=mx"
|
136
|
+
expect(@controller.resources_url).to eq("/admin/users?q=mx")
|
137
|
+
end
|
138
|
+
end
|
139
|
+
describe "nested GET" do
|
140
|
+
it "/users/1/posts" do
|
141
|
+
user = User.create! id: 1, login: "test"
|
142
|
+
get "/users/1/posts"
|
143
|
+
expect(@controller.resources_url).to eq("/users/1/posts?user_id=1&ids=[]&perpage=20&page=1")
|
28
144
|
|
29
|
-
it "gets all posts to a user" do
|
30
|
-
user = User.create(login: 'fisk')
|
31
|
-
post = Post.create(user: user, title: 'fisk')
|
32
|
-
get user_posts_path(user_id: user.id)
|
33
|
-
expect(@controller.parent?).to eq true
|
34
|
-
expect(@controller.resources_url).to eq "/users/1/posts"
|
35
|
-
expect(@controller.resources.first).to eq (post)
|
36
145
|
end
|
146
|
+
it "/users/1/posts/1" do
|
147
|
+
user = User.create! id: 1, login: "test"
|
148
|
+
post = Post.create! id: 1, user_id: user.id, title: "test"
|
149
|
+
get "/users/1/posts/1"
|
150
|
+
expect(@controller.resources_url).to eq("/users/1/posts?user_id=1")
|
37
151
|
|
152
|
+
end
|
153
|
+
it "/admin/users" do
|
154
|
+
get "/admin/users"
|
155
|
+
expect(@controller.resources_url).to eq("/admin/users?ids=[]&perpage=20&page=1")
|
156
|
+
end
|
157
|
+
it "/admin/users/1" do
|
158
|
+
user = User.create! id: 1, login: "test"
|
159
|
+
get "/admin/users/1"
|
160
|
+
expect(@controller.resources_url).to eq("/admin/users")
|
161
|
+
end
|
162
|
+
it "/users/1" do
|
163
|
+
user = User.create! id: 1, login: "test"
|
164
|
+
get "/users/1"
|
165
|
+
expect(@controller.resources_url).to eq("/users")
|
166
|
+
end
|
167
|
+
it "/admin/users/1?q=mx" do
|
168
|
+
user = User.create! id: 1, login: "test"
|
169
|
+
get "/admin/users/1?q=mx"
|
170
|
+
expect(@controller.resources_url).to eq("/admin/users?q=mx")
|
171
|
+
end
|
38
172
|
end
|
39
|
-
|
40
173
|
end
|
41
174
|
|
175
|
+
|
176
|
+
# RSpec.describe Admin::UsersController, type: :controller do
|
177
|
+
#
|
178
|
+
#
|
179
|
+
# end
|
180
|
+
|
42
181
|
RSpec.describe UsersController, type: :controller do
|
43
182
|
|
44
183
|
|
@@ -61,178 +200,179 @@ RSpec.describe UsersController, type: :controller do
|
|
61
200
|
# in order to pass any filters (e.g. authentication) defined in
|
62
201
|
# UsersController. Be sure to keep this updated too.
|
63
202
|
let(:valid_session) { {} }
|
203
|
+
#
|
204
|
+
# describe "GET #index" do
|
205
|
+
# it "assigns all users as @resources" do
|
206
|
+
# user = User.create! valid_attributes
|
207
|
+
# get :index, {}, valid_session
|
208
|
+
# expect(assigns(:resources)).to eq([user])
|
209
|
+
# end
|
210
|
+
# end
|
211
|
+
#
|
212
|
+
# describe "GET #show" do
|
213
|
+
# it "assigns the requested user as @resource" do
|
214
|
+
# user = User.create! valid_attributes
|
215
|
+
# get :show, {:id => user.to_param}, valid_session
|
216
|
+
# expect(assigns(:resource)).to eq(user)
|
217
|
+
# end
|
218
|
+
# end
|
219
|
+
#
|
220
|
+
#
|
221
|
+
# describe "GET #new" do
|
222
|
+
# it "assigns a new user as @resource" do
|
223
|
+
# get :new, {}, valid_session
|
224
|
+
# expect(assigns(:resource)).to be_a_new(User)
|
225
|
+
# end
|
226
|
+
# end
|
227
|
+
#
|
228
|
+
# describe "GET #edit" do
|
229
|
+
# it "assigns the requested user as @resource" do
|
230
|
+
# user = User.create! valid_attributes
|
231
|
+
# get :edit, {:id => user.to_param}, valid_session
|
232
|
+
# expect(assigns(:resource)).to eq(user)
|
233
|
+
# end
|
234
|
+
# end
|
235
|
+
#
|
236
|
+
# describe "POST #create" do
|
237
|
+
# context "with valid params" do
|
238
|
+
# it "creates a new User" do
|
239
|
+
# expect {
|
240
|
+
# post :create, {:user => valid_attributes}, valid_session
|
241
|
+
# }.to change(User, :count).by(1)
|
242
|
+
# end
|
243
|
+
#
|
244
|
+
# it "assigns a newly created user as @resource" do
|
245
|
+
# post :create, {:user => valid_attributes}, valid_session
|
246
|
+
# expect(assigns(:resource)).to be_a(User)
|
247
|
+
# expect(assigns(:resource)).to be_persisted
|
248
|
+
# end
|
249
|
+
#
|
250
|
+
# it "redirects to the list of users, as @resources" do
|
251
|
+
# post :create, {:user => valid_attributes}, valid_session
|
252
|
+
# expect(response).to redirect_to(users_url)
|
253
|
+
# end
|
254
|
+
# end
|
255
|
+
#
|
256
|
+
# # with Rails 4.x strong_parameters and Responders, forms with invalid attributes
|
257
|
+
# # will silently fail - thus depriving haxors any idea of the issues
|
258
|
+
# #
|
259
|
+
# # context "with invalid params" do
|
260
|
+
# # it "assigns a newly created but unsaved user as @user" do
|
261
|
+
# # post :create, {:user => invalid_attributes}, valid_session
|
262
|
+
# # expect(assigns(:resource)).to be_a_new(User)
|
263
|
+
# # end
|
264
|
+
# #
|
265
|
+
# # it "re-renders the 'new' template" do
|
266
|
+
# # post :create, {:user => invalid_attributes}, valid_session
|
267
|
+
# # expect(response).to render_template("new")
|
268
|
+
# # end
|
269
|
+
# # end
|
270
|
+
# end
|
271
|
+
#
|
272
|
+
# describe "PUT #update" do
|
273
|
+
# context "with valid params" do
|
274
|
+
# let(:new_attributes) {
|
275
|
+
# { login: 'mil'}
|
276
|
+
# }
|
277
|
+
#
|
278
|
+
# it "updates the requested @resource" do
|
279
|
+
# user = User.create! valid_attributes
|
280
|
+
# put :update, {:id => user.to_param, :user => new_attributes}, valid_session
|
281
|
+
# user.reload
|
282
|
+
# expect(user.login).to eq('mil')
|
283
|
+
# end
|
284
|
+
#
|
285
|
+
# it "assigns the requested user as @resource" do
|
286
|
+
# user = User.create! valid_attributes
|
287
|
+
# put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
|
288
|
+
# expect(assigns(:resource)).to eq(user)
|
289
|
+
# end
|
290
|
+
#
|
291
|
+
# it "redirects to list of users" do
|
292
|
+
# user = User.create! valid_attributes
|
293
|
+
# put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
|
294
|
+
# expect(response).to redirect_to(users_url)
|
295
|
+
# end
|
296
|
+
# end
|
297
|
+
#
|
298
|
+
# # with Rails 4.x strong_parameters and Responders, forms with invalid attributes
|
299
|
+
# # will silently fail - thus depriving haxors any idea of the issues
|
300
|
+
# #
|
301
|
+
# context "with invalid params" do
|
302
|
+
# it "assigns the user as @resource" do
|
303
|
+
# user = User.create! valid_attributes
|
304
|
+
# put :update, {:id => user.to_param, :user => invalid_attributes}, valid_session
|
305
|
+
# expect(assigns(:resource)).to eq(user)
|
306
|
+
# end
|
307
|
+
# #
|
308
|
+
# # it "re-renders the 'edit' template" do
|
309
|
+
# # user = User.create! valid_attributes
|
310
|
+
# # put :update, {:id => user.to_param, :user => invalid_attributes}, valid_session
|
311
|
+
# # expect(response).to render_template("edit")
|
312
|
+
# # end
|
313
|
+
# end
|
314
|
+
# end
|
315
|
+
#
|
316
|
+
# describe "DELETE #destroy" do
|
317
|
+
# it "destroys the requested user" do
|
318
|
+
# user = User.create! valid_attributes
|
319
|
+
# expect {
|
320
|
+
# delete :destroy, {:id => user.to_param}, valid_session
|
321
|
+
# }.to change(User, :count).by(-1)
|
322
|
+
# end
|
323
|
+
#
|
324
|
+
# it "redirects to the users list" do
|
325
|
+
# user = User.create! valid_attributes
|
326
|
+
# delete :destroy, {:id => user.to_param}, valid_session
|
327
|
+
# expect(response).to redirect_to(users_url)
|
328
|
+
# end
|
329
|
+
# end
|
64
330
|
|
65
|
-
describe "GET #index" do
|
66
|
-
it "assigns all users as @resources" do
|
67
|
-
user = User.create! valid_attributes
|
68
|
-
get :index, {}, valid_session
|
69
|
-
expect(assigns(:resources)).to eq([user])
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "GET #show" do
|
74
|
-
it "assigns the requested user as @resource" do
|
75
|
-
user = User.create! valid_attributes
|
76
|
-
get :show, {:id => user.to_param}, valid_session
|
77
|
-
expect(assigns(:resource)).to eq(user)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
describe "GET #new" do
|
83
|
-
it "assigns a new user as @resource" do
|
84
|
-
get :new, {}, valid_session
|
85
|
-
expect(assigns(:resource)).to be_a_new(User)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "GET #edit" do
|
90
|
-
it "assigns the requested user as @resource" do
|
91
|
-
user = User.create! valid_attributes
|
92
|
-
get :edit, {:id => user.to_param}, valid_session
|
93
|
-
expect(assigns(:resource)).to eq(user)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe "POST #create" do
|
98
|
-
context "with valid params" do
|
99
|
-
it "creates a new User" do
|
100
|
-
expect {
|
101
|
-
post :create, {:user => valid_attributes}, valid_session
|
102
|
-
}.to change(User, :count).by(1)
|
103
|
-
end
|
104
331
|
|
105
|
-
|
106
|
-
post :create, {:user => valid_attributes}, valid_session
|
107
|
-
expect(assigns(:resource)).to be_a(User)
|
108
|
-
expect(assigns(:resource)).to be_persisted
|
109
|
-
end
|
332
|
+
describe "inherited methods to verify resources, classes and names" do
|
110
333
|
|
111
|
-
it "redirects to the list of users, as @resources" do
|
112
|
-
post :create, {:user => valid_attributes}, valid_session
|
113
|
-
expect(response).to redirect_to(users_url)
|
114
|
-
end
|
115
|
-
end
|
116
334
|
|
117
|
-
#
|
118
|
-
#
|
335
|
+
# it "any action should respond to parent?" do
|
336
|
+
# get :index
|
337
|
+
# expect(@controller.parent?).to eq(false)
|
338
|
+
# end
|
119
339
|
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
# end
|
340
|
+
# it "any action should respond to resource" do
|
341
|
+
# get :new
|
342
|
+
# expect(@controller.resource).not_to eq(nil)
|
343
|
+
# end
|
125
344
|
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
# end
|
345
|
+
# it "index action should respond to resources" do
|
346
|
+
# get :index
|
347
|
+
# expect(@controller.resources).not_to eq(nil)
|
130
348
|
# end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "PUT #update" do
|
134
|
-
context "with valid params" do
|
135
|
-
let(:new_attributes) {
|
136
|
-
{ login: 'mil'}
|
137
|
-
}
|
138
|
-
|
139
|
-
it "updates the requested @resource" do
|
140
|
-
user = User.create! valid_attributes
|
141
|
-
put :update, {:id => user.to_param, :user => new_attributes}, valid_session
|
142
|
-
user.reload
|
143
|
-
expect(user.login).to eq('mil')
|
144
|
-
end
|
145
|
-
|
146
|
-
it "assigns the requested user as @resource" do
|
147
|
-
user = User.create! valid_attributes
|
148
|
-
put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
|
149
|
-
expect(assigns(:resource)).to eq(user)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "redirects to list of users" do
|
153
|
-
user = User.create! valid_attributes
|
154
|
-
put :update, {:id => user.to_param, :user => valid_attributes}, valid_session
|
155
|
-
expect(response).to redirect_to(users_url)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
# with Rails 4.x strong_parameters and Responders, forms with invalid attributes
|
160
|
-
# will silently fail - thus depriving haxors any idea of the issues
|
161
349
|
#
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
expect(assigns(:resource)).to eq(user)
|
167
|
-
end
|
350
|
+
# it "any action should respond to resource_class" do
|
351
|
+
# get :new
|
352
|
+
# expect(@controller.resource_class).to eq(User)
|
353
|
+
# end
|
168
354
|
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
#
|
173
|
-
#
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
end
|
184
|
-
|
185
|
-
it "
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
|
193
|
-
describe "inherited methods to verify resources, classes and names" do
|
194
|
-
|
195
|
-
it "any action should respond to parent?" do
|
196
|
-
get :index
|
197
|
-
expect(@controller.parent?).to eq(false)
|
198
|
-
end
|
199
|
-
|
200
|
-
it "any action should respond to resource" do
|
201
|
-
get :new
|
202
|
-
expect(@controller.resource).not_to eq(nil)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "index action should respond to resources" do
|
206
|
-
get :index
|
207
|
-
expect(@controller.resources).not_to eq(nil)
|
208
|
-
end
|
209
|
-
|
210
|
-
it "any action should respond to resource_class" do
|
211
|
-
get :new
|
212
|
-
expect(@controller.resource_class).to eq(User)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "any action should respond to resource_name" do
|
216
|
-
get :new
|
217
|
-
expect(@controller.resource_name).to eq('users')
|
218
|
-
end
|
219
|
-
|
220
|
-
it "any action should respond to parent_class" do
|
221
|
-
get :new
|
222
|
-
expect(@controller.parent_class).to eq(NilClass)
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should return a url on the resource" do
|
226
|
-
user = User.create! valid_attributes
|
227
|
-
response = get :show, {:id => user.to_param, murky: '2'}, valid_session
|
228
|
-
expect(@controller.resource_url).to eq "/users/#{user.id}?murky=2"
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should return a url on the resources" do
|
232
|
-
user = User.create! valid_attributes
|
233
|
-
get :index, {:id => user.to_param}, valid_session
|
234
|
-
expect(@controller.resources_url).to eq "/users"
|
235
|
-
end
|
355
|
+
# it "any action should respond to resource_name" do
|
356
|
+
# get :new
|
357
|
+
# expect(@controller.resource_name).to eq('users')
|
358
|
+
# end
|
359
|
+
#
|
360
|
+
# it "any action should respond to parent_class" do
|
361
|
+
# get :new
|
362
|
+
# expect(@controller.parent_class).to eq(NilClass)
|
363
|
+
# end
|
364
|
+
#
|
365
|
+
# it "should return a url on the resource" do
|
366
|
+
# user = User.create! valid_attributes
|
367
|
+
# response = get :show, {:id => user.to_param, murky: '2'}, valid_session
|
368
|
+
# expect(@controller.resource_url).to eq "/users/#{user.id}?murky=2"
|
369
|
+
# end
|
370
|
+
#
|
371
|
+
# it "should return a url on the resources" do
|
372
|
+
# user = User.create! valid_attributes
|
373
|
+
# get :index, {:id => user.to_param}, valid_session
|
374
|
+
# expect(@controller.resources_url).to eq "/users"
|
375
|
+
# end
|
236
376
|
|
237
377
|
end
|
238
378
|
|