jcontroller 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jcontroller/controller_helpers.rb +5 -3
- data/lib/jcontroller/version.rb +1 -1
- data/spec/fake_app/app/assets/javascripts/application.js +6 -3
- data/spec/fake_app/app/controllers.rb +1 -2
- data/spec/fake_app/app/views/users/parameters_template.html.erb +1 -0
- data/spec/fake_app/app/views/users/parameters_template.js.jbuilder +1 -0
- data/spec/fake_app/app/views/users/parameters_template_params.js.jbuilder +1 -1
- data/spec/features/jcontroller_spec.rb +26 -9
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd4eddc629591228381b3f2e89830d0b4dfad727
|
4
|
+
data.tar.gz: e9e32d5f448c8d123120da86e1ccb90b05024675
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75409726a27d522e8f362def93c1bec0bb4b970dc0e049f91172ce3657f54e95105b4295631b8478771d53fc44499059c7120d29fa4d49aebdb40dbadf8c5ae6
|
7
|
+
data.tar.gz: 96cdec26675bc6f59096186803ffb9ce266c9befb065e7c2e1e1082b5ae7d00c525c22496059601ba46348900ce3ba9e989e9a61cabc90aba28b1e2897eee437
|
@@ -52,9 +52,11 @@ module Jcontroller
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def jcontroller_params(action)
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
if formats.first == :html
|
56
|
+
with_format :js do
|
57
|
+
if lookup_context.template_exists? action.params_template_path
|
58
|
+
view_context.render(:template => action.params_template_path)
|
59
|
+
end
|
58
60
|
end
|
59
61
|
end
|
60
62
|
end
|
data/lib/jcontroller/version.rb
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
//= require_tree .
|
5
5
|
|
6
6
|
test_append_selector = '#test_append';
|
7
|
-
test_append = function(controller_namespace, filter, params) {
|
7
|
+
test_append = function(controller_namespace, filter, format, params) {
|
8
8
|
var $div = $(document.createElement('div'));
|
9
|
-
$div.attr("filter", controller_namespace + "/" +
|
9
|
+
$div.attr("filter", controller_namespace + "/" + format + "/" + filter);
|
10
10
|
$div.append(params.s);
|
11
11
|
$(test_append_selector).append($div);
|
12
12
|
};
|
@@ -16,7 +16,7 @@ create_routes = function(controller_path, extend) {
|
|
16
16
|
$.each(filters, function(index, filter) {
|
17
17
|
hash[format][filter] = function(params, state) {
|
18
18
|
if (this.params.s === params.s && this.state.action_name === state.action_name) {
|
19
|
-
test_append(controller_path, filter, this.params);
|
19
|
+
test_append(controller_path, filter, format, this.params);
|
20
20
|
}
|
21
21
|
}
|
22
22
|
});
|
@@ -26,6 +26,9 @@ create_routes = function(controller_path, extend) {
|
|
26
26
|
hash.html.state = function() {
|
27
27
|
$(test_append_selector).html(JSON.stringify(this.state));
|
28
28
|
};
|
29
|
+
hash.js.parameters_template = function() {
|
30
|
+
test_append(controller_path, 'parameters_template', "js", this.params);
|
31
|
+
};
|
29
32
|
set_basic_filters('html', ["before", "after", "index", "redirect", "redirect_simple",
|
30
33
|
"manually_execute", "manual_parameters", "parameters_template"]);
|
31
34
|
set_basic_filters('js', ["before", "after", "index"]);
|
@@ -11,11 +11,10 @@ class UsersController < ApplicationController
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def parameters_template
|
14
|
-
@parameter_string = "parameter template"
|
14
|
+
@parameter_string = "parameter template #{formats.first}"
|
15
15
|
end
|
16
16
|
|
17
17
|
def stopped
|
18
|
-
Jcontroller.ajax = !params[:ajax_off]
|
19
18
|
js false
|
20
19
|
end
|
21
20
|
def redirect
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= link_to "ajax link", parameters_template_users_path, remote: true, onclick: "$(test_append_selector).empty();" %>
|
@@ -0,0 +1 @@
|
|
1
|
+
json.s @parameter_string
|
@@ -1 +1 @@
|
|
1
|
-
json.s @parameter_string
|
1
|
+
json.s @parameter_string + "_params"
|
@@ -9,12 +9,14 @@ feature 'invoke correct filter', :js => true do
|
|
9
9
|
"#{controller_namespace}/#{format}/#{filter}"
|
10
10
|
end
|
11
11
|
|
12
|
-
def filters(controller_namespace, action,
|
13
|
-
|
12
|
+
def filters(controller_namespace, action, options={})
|
13
|
+
options = options.reverse_merge({ :parent_namespaces => %w[application], :format => "html" })
|
14
|
+
|
15
|
+
controller_namespaces = options[:parent_namespaces] + [controller_namespace]
|
14
16
|
filters = []
|
15
|
-
filters += controller_namespaces.map {|controller_namespace| filter_namespace(controller_namespace, "before") }
|
16
|
-
filters += controller_namespaces.map {|controller_namespace| filter_namespace(controller_namespace, action) }
|
17
|
-
filters + controller_namespaces.map {|controller_namespace| filter_namespace(controller_namespace, "after") }.reverse
|
17
|
+
filters += controller_namespaces.map {|controller_namespace| filter_namespace(controller_namespace, "before", options[:format]) }
|
18
|
+
filters += controller_namespaces.map {|controller_namespace| filter_namespace(controller_namespace, action, options[:format]) }
|
19
|
+
filters + controller_namespaces.map {|controller_namespace| filter_namespace(controller_namespace, "after", options[:format]) }.reverse
|
18
20
|
end
|
19
21
|
|
20
22
|
def test_elements(filters, parameters="")
|
@@ -59,7 +61,7 @@ feature 'invoke correct filter', :js => true do
|
|
59
61
|
end
|
60
62
|
scenario 'with superclassed controller' do
|
61
63
|
visit superusers_path
|
62
|
-
test_elements filters('superusers', "index", %w[application users])
|
64
|
+
test_elements filters('superusers', "index", { :parent_namespaces => %w[application users]})
|
63
65
|
end
|
64
66
|
scenario 'with empty parent controller' do
|
65
67
|
visit empty_parents_path
|
@@ -106,12 +108,20 @@ feature 'invoke correct filter', :js => true do
|
|
106
108
|
end
|
107
109
|
scenario 'with parameters template' do
|
108
110
|
visit parameters_template_users_path
|
109
|
-
test_elements filters('users', "parameters_template"), "parameter template"
|
111
|
+
test_elements filters('users', "parameters_template"), "parameter template html_params"
|
110
112
|
end
|
111
113
|
|
112
114
|
context "with ajax" do
|
115
|
+
before :each do
|
116
|
+
Jcontroller.ajax = true
|
117
|
+
end
|
118
|
+
after :each do
|
119
|
+
Jcontroller.ajax = nil
|
120
|
+
end
|
121
|
+
|
113
122
|
scenario "ajax off" do
|
114
|
-
|
123
|
+
Jcontroller.ajax = nil
|
124
|
+
visit stopped_users_path
|
115
125
|
click_link "ajax link"
|
116
126
|
wait_for_ajax
|
117
127
|
test_no_elements
|
@@ -121,7 +131,14 @@ feature 'invoke correct filter', :js => true do
|
|
121
131
|
visit stopped_users_path
|
122
132
|
click_link "ajax link"
|
123
133
|
wait_for_ajax
|
124
|
-
test_elements filters('users', "index"), "ajax parameter"
|
134
|
+
test_elements filters('users', "index", { :format => "js"}), "ajax parameter"
|
135
|
+
end
|
136
|
+
|
137
|
+
scenario "with _params template existing" do
|
138
|
+
visit parameters_template_users_path
|
139
|
+
click_link "ajax link"
|
140
|
+
wait_for_ajax
|
141
|
+
test_elements filters('users', "parameters_template", { :format => "js"}), "parameter template js"
|
125
142
|
end
|
126
143
|
end
|
127
144
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jcontroller
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Chung
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- spec/fake_app/app/views/users/manually_execute.html.erb
|
183
183
|
- spec/fake_app/app/views/users/no_action.html.erb
|
184
184
|
- spec/fake_app/app/views/users/parameters_template.html.erb
|
185
|
+
- spec/fake_app/app/views/users/parameters_template.js.jbuilder
|
185
186
|
- spec/fake_app/app/views/users/parameters_template_params.js.jbuilder
|
186
187
|
- spec/fake_app/app/views/users/redirect_params.js.jbuilder
|
187
188
|
- spec/fake_app/app/views/users/state.html.erb
|
@@ -237,6 +238,7 @@ test_files:
|
|
237
238
|
- spec/fake_app/app/views/users/manually_execute.html.erb
|
238
239
|
- spec/fake_app/app/views/users/no_action.html.erb
|
239
240
|
- spec/fake_app/app/views/users/parameters_template.html.erb
|
241
|
+
- spec/fake_app/app/views/users/parameters_template.js.jbuilder
|
240
242
|
- spec/fake_app/app/views/users/parameters_template_params.js.jbuilder
|
241
243
|
- spec/fake_app/app/views/users/redirect_params.js.jbuilder
|
242
244
|
- spec/fake_app/app/views/users/state.html.erb
|