thin_man 0.19.6 → 0.19.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,8 @@ module ThinMan
29
29
  sub_class: nil, insert_method: nil, empty_on_success: nil, remove_on_success: nil,
30
30
  http_method: nil, no_mouse_click: nil, progress_target: nil,
31
31
  progress_color: nil, mask_target: nil, mask_message: nil,
32
- sequence_group: nil, sequence_number: nil)
32
+ sequence_group: nil, sequence_number: nil,
33
+ search_path: nil, search_params: nil)
33
34
  ajax_options = {
34
35
  'data-ajax-link-now' => true,
35
36
  'data-ajax-target' => target
@@ -46,6 +47,8 @@ module ThinMan
46
47
  ajax_options.merge!('data-mask-message' => mask_message) if mask_message.present?
47
48
  ajax_options.merge!('data-sequence-group' => sequence_group) if sequence_group.present?
48
49
  ajax_options.merge!('data-sequence-number' => sequence_number) if sequence_number.present?
50
+ ajax_options.merge!('data-search-path' => search_path) if search_path.present?
51
+ ajax_options.merge!('data-search-params' => search_params) if search_params.present?
49
52
  link_to(name,
50
53
  options,
51
54
  html_options.merge(ajax_options))
@@ -1,3 +1,3 @@
1
1
  module ThinMan
2
- VERSION = "0.19.6"
2
+ VERSION = "0.19.7"
3
3
  end
@@ -2,75 +2,70 @@
2
2
  // Generated on Thu Sep 10 2015 16:43:39 GMT-0500 (COT)
3
3
 
4
4
  module.exports = function(config) {
5
- config.set({
5
+ config.set({
6
6
 
7
- // base path that will be used to resolve all patterns (eg. files, exclude)
8
- basePath: '',
7
+ // base path that will be used to resolve all patterns (eg. files, exclude)
8
+ basePath: '',
9
9
 
10
10
 
11
- // frameworks to use
12
- // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13
- frameworks: ['jasmine-ajax', 'jasmine', 'requirejs'],
11
+ // frameworks to use
12
+ // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13
+ frameworks: ['jasmine-ajax', 'jasmine', 'requirejs'],
14
14
 
15
15
 
16
- // list of files / patterns to load in the browser
17
- files: [
18
- 'test-main.js',
19
- { pattern: 'jquery.js' },
20
- { pattern: 'jasmine-fixture.js' },
21
- { pattern: '../../app/assets/javascripts/thin_man.js' },
22
- { pattern: '../../app/assets/javascripts/debug_logger.js' },
23
- { pattern: 'spec/helpers/*.js' },
24
- { pattern: 'spec/**/*Spec.js', included: false }
25
- ],
16
+ // list of files / patterns to load in the browser
17
+ files: [
18
+ 'test-main.js',
19
+ {pattern: 'jquery.js'},
20
+ {pattern: 'jasmine-fixture.js'},
21
+ {pattern: '../../app/assets/javascripts/thin_man.js'},
22
+ {pattern: '../../app/assets/javascripts/debug_logger.js'},
23
+ {pattern: 'spec/helpers/*.js'},
24
+ {pattern: 'spec/**/*Spec.js', included: false}
25
+ ],
26
26
 
27
27
 
28
- // list of files to exclude
29
- exclude: [],
28
+ // list of files to exclude
29
+ exclude: [
30
+ ],
30
31
 
31
32
 
32
- // preprocess matching files before serving them to the browser
33
- // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
34
- preprocessors: {},
33
+ // preprocess matching files before serving them to the browser
34
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
35
+ preprocessors: {
36
+ },
35
37
 
36
38
 
37
- // test results reporter to use
38
- // possible values: 'dots', 'progress'
39
- // available reporters: https://npmjs.org/browse/keyword/karma-reporter
40
- reporters: ['spec'],
39
+ // test results reporter to use
40
+ // possible values: 'dots', 'progress'
41
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
42
+ reporters: ['spec'],
41
43
 
42
44
 
43
- // web server port
44
- port: 9876,
45
+ // web server port
46
+ port: 9876,
45
47
 
46
48
 
47
- // enable / disable colors in the output (reporters and logs)
48
- colors: true,
49
+ // enable / disable colors in the output (reporters and logs)
50
+ colors: true,
49
51
 
50
52
 
51
- // level of logging
52
- // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
53
- logLevel: config.LOG_INFO,
53
+ // level of logging
54
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
55
+ logLevel: config.LOG_INFO,
54
56
 
55
57
 
56
- // enable / disable watching file and executing tests whenever any file changes
57
- autoWatch: false,
58
+ // enable / disable watching file and executing tests whenever any file changes
59
+ autoWatch: false,
58
60
 
59
61
 
60
- // start these browsers
61
- // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
62
- browsers: ['PhantomJS'],
63
- // customLaunchers: {
64
- // 'PhantomJS_custom': {
65
- // base: 'PhantomJS',
66
- // debug: true,
67
- // },
68
- // },
69
- // browsers: ['Chrome'],
62
+ // start these browsers
63
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
64
+ browsers: ['PhantomJS'],
70
65
 
71
66
 
72
- // Continuous Integration mode
73
- // if true, Karma captures browsers, runs the tests and exits
74
- singleRun: true
75
- })
76
- }
67
+ // Continuous Integration mode
68
+ // if true, Karma captures browsers, runs the tests and exits
69
+ singleRun: true
70
+ })
71
+ }
@@ -1,272 +1,242 @@
1
- describe("thin_man", function() {
1
+ describe("thin_man", function(){
2
2
 
3
- function getAjaxArg(arg_name) {
4
- return $.ajax.calls.argsFor(0)[0][arg_name];
5
- }
3
+ function getAjaxArg(arg_name){
4
+ return $.ajax.calls.argsFor(0)[0][arg_name];
5
+ }
6
6
 
7
- describe("Base class", function() {
8
- beforeAll(function() {
9
- jasmine.Ajax.install();
10
- jasmine.clock().install();
11
- });
7
+ describe("Base class", function(){
8
+ beforeAll(function(){
9
+ jasmine.Ajax.install();
10
+ jasmine.clock().install();
11
+ });
12
+
13
+ describe(".ajaxSuccess", function(){
14
+ var $link, $target, thin;
15
+
16
+ beforeEach(function(){
17
+ $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
18
+ $target = affix('#test_dom_id');
19
+ thin = new thin_man.AjaxLinkSubmission($link);
20
+ });
21
+
22
+ it("Add result to the target", function(){
23
+ thin.ajaxSuccess({ html: "Hello" }, 'success', TestResponses.success)
24
+ expect($target.html()).toEqual("Hello")
25
+ });
26
+
27
+ it("focus on first element", function(){
28
+ var form = '<form><input type="text"><textarea>dummy</textarea></form>'
29
+ thin.ajaxSuccess(form, 'success', TestResponses.success)
30
+ expect($target.html()).toEqual(form);
31
+ expect($("[type='text']").length).toEqual(1);
32
+ //Check if it's focused
33
+ expect($("[type='text']").get(0)).toBe(document.activeElement);
34
+ });
35
+
36
+ it("empties the target if there is no html in the json", function(){
37
+ $target.html('Remove me.')
38
+ thin.ajaxSuccess({flash_message: 'Successfully moved the widget.'}, 'success', TestResponses.success)
39
+ expect($target.html()).toEqual('')
40
+ })
41
+
42
+ it("handles success with no target", function(){
43
+ $no_target_link = affix('a[data-ajax-link="true"][data-ajax-target=""]');
44
+ thin = new thin_man.AjaxLinkSubmission($no_target_link);
45
+ thin.ajaxSuccess({flash_message: 'Success'},'success', TestResponses.success)
46
+ })
47
+ });
48
+
49
+ describe(".ajaxComplete", function(){
50
+ var $link, thin;
12
51
 
13
- describe(".ajaxSuccess", function() {
14
- var $link, $target, thin;
15
-
16
- beforeEach(function() {
17
- $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
18
- $target = affix('#test_dom_id');
19
- thin = new thin_man.AjaxLinkSubmission($link);
20
- });
21
-
22
- it("Add result to the target", function() {
23
- thin.ajaxSuccess({ html: "Hello" }, 'success', TestResponses.success)
24
- expect($target.html()).toEqual("Hello")
25
- });
26
-
27
- it("focus on first element", function() {
28
- var form = '<form><input type="text"><textarea>dummy</textarea></form>'
29
- thin.ajaxSuccess(form, 'success', TestResponses.success)
30
- expect($target.html()).toEqual(form);
31
- expect($("[type='text']").length).toEqual(1);
32
- //Check if it's focused
33
- expect($("[type='text']").get(0)).toBe(document.activeElement);
34
- });
35
-
36
- it("empties the target if there is no html in the json", function() {
37
- $target.html('Remove me.')
38
- thin.ajaxSuccess({ flash_message: 'Successfully moved the widget.' }, 'success', TestResponses.success)
39
- expect($target.html()).toEqual('')
40
- })
41
-
42
- it("handles success with no target", function() {
43
- $no_target_link = affix('a[data-ajax-link="true"][data-ajax-target=""]');
44
- thin = new thin_man.AjaxLinkSubmission($no_target_link);
45
- thin.ajaxSuccess({ flash_message: 'Success' }, 'success', TestResponses.success)
46
- })
52
+ beforeEach(function(){
53
+ $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"] #test_dom_id');
54
+ affix('[data-thin-man-flash-template] [data-thin-man-flash-content]');
55
+ thin = new thin_man.AjaxLinkSubmission($link);
56
+ });
57
+
58
+ describe("Display flash message", function(){
59
+ it("successfully response", function(){
60
+ thin.ajaxComplete(TestResponses.success);
61
+ expect(thin.flash.flash_content.text()).toMatch('successfully response');
47
62
  });
48
63
 
49
- describe(".ajaxComplete", function() {
50
- var $link, thin;
51
-
52
- beforeEach(function() {
53
- $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"] #test_dom_id');
54
- affix('[data-thin-man-flash-template] [data-thin-man-flash-content]');
55
- thin = new thin_man.AjaxLinkSubmission($link);
56
- });
57
-
58
- describe("Display flash message", function() {
59
- it("successfully response", function() {
60
- thin.ajaxComplete(TestResponses.success);
61
- expect(thin.flash.flash_content.text()).toMatch('successfully response');
62
- });
63
-
64
- it("error response", function() {
65
- thin.ajaxComplete(TestResponses.error);
66
- expect(thin.flash.flash_content.text()).toMatch('error response');
67
- });
68
- });
69
-
70
- it("fade out if flash_persist is false", function() {
71
- spyOn($.fn, 'fadeOut');
72
- thin.ajaxComplete(TestResponses.success);
73
- jasmine.clock().tick(2000);
74
- expect($.fn.fadeOut).toHaveBeenCalled();
75
- });
64
+ it("error response", function(){
65
+ thin.ajaxComplete(TestResponses.error);
66
+ expect(thin.flash.flash_content.text()).toMatch('error response');
76
67
  });
68
+ });
69
+
70
+ it("fade out if flash_persist is false", function(){
71
+ spyOn($.fn, 'fadeOut');
72
+ thin.ajaxComplete(TestResponses.success);
73
+ jasmine.clock().tick(2000);
74
+ expect($.fn.fadeOut).toHaveBeenCalled();
75
+ });
76
+ });
77
77
 
78
- describe(".ajaxError", function() {
79
- var $link, thin;
78
+ describe(".ajaxError", function(){
79
+ var $link, thin;
80
80
 
81
- beforeEach(function() {
82
- $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
83
- $target = affix('#test_dom_id');
84
- thin = new thin_man.AjaxLinkSubmission($link);
85
- });
81
+ beforeEach(function(){
82
+ $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
83
+ $target = affix('#test_dom_id');
84
+ thin = new thin_man.AjaxLinkSubmission($link);
85
+ });
86
86
 
87
- it('as a string', function() {
88
- thin.ajaxError(TestResponses.conflictString);
89
- expect($('#test_dom_id').html()).toMatch('conflict string response');
90
- });
87
+ it('as a string', function(){
88
+ thin.ajaxError(TestResponses.conflictString);
89
+ expect($('#test_dom_id').html()).toMatch('conflict string response');
90
+ });
91
91
 
92
- it('as an object', function() {
93
- thin.ajaxError(TestResponses.conflict);
94
- expect($('#test_dom_id').html()).toMatch('Required field');
95
- });
92
+ it('as an object', function(){
93
+ thin.ajaxError(TestResponses.conflict);
94
+ expect($('#test_dom_id').html()).toMatch('Required field');
95
+ });
96
96
 
97
- });
98
97
  });
99
-
100
- describe("AjaxLinkSubmission", function() {
101
- it("submits an ajax call with options", function() {
102
- var $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-return-type="json"]');
103
- thin_man.AjaxLinkSubmission($link)
104
- spyOn($, 'ajax');
105
- $link.click();
106
- expect($.ajax).toHaveBeenCalled();
107
- expect(getAjaxArg("url")).toMatch("/url");
108
- expect(getAjaxArg("type")).toMatch("PATCH");
109
- expect(getAjaxArg("datatype")).toMatch("json");
110
- expect(thin_man.hasOwnProperty('link_groups')).toEqual(false)
111
- });
112
- it("fires grouped links in sequence", function() {
113
- var $link_zero = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="0"]');
114
- var $link_one = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="1"]');
115
- var $link_two = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="2"]');
116
- zero = new thin_man.AjaxLinkSubmission($link_zero)
117
- one = new thin_man.AjaxLinkSubmission($link_one)
118
- two = new thin_man.AjaxLinkSubmission($link_two)
119
- expect(thin_man.hasOwnProperty('link_groups')).toEqual(true)
120
- spyOn(one, 'fire')
121
- spyOn(two, 'fire')
122
- zero.ajaxComplete()
123
- expect(one.fire).toHaveBeenCalled();
124
- expect(two.fire).not.toHaveBeenCalled();
125
- one.ajaxComplete()
126
- expect(one.fire.calls.count()).toEqual(1);
127
- expect(two.fire).toHaveBeenCalled();
128
- })
98
+ });
99
+
100
+ describe("AjaxLinkSubmission", function(){
101
+ it("submits an ajax call with options", function(){
102
+ var $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-return-type="json"]');
103
+ thin_man.AjaxLinkSubmission($link)
104
+ spyOn($, 'ajax');
105
+ $link.click();
106
+ expect($.ajax).toHaveBeenCalled();
107
+ expect(getAjaxArg("url")).toMatch("/url");
108
+ expect(getAjaxArg("type")).toMatch("PATCH");
109
+ expect(getAjaxArg("datatype")).toMatch("json");
110
+ expect(thin_man.hasOwnProperty('link_groups')).toEqual(false)
129
111
  });
130
- describe("DeleteLink", function() {
131
- it("submits an ajax delete call with options", function() {
132
- var $link = affix('a[data-ajax-delete="true"][data-ajax-target="#test_dom_id"][href="/url"]');
133
- var delete_link = new thin_man.DeleteLink($link)
134
- spyOn($, 'ajax');
135
- $link.click();
136
- expect($.ajax).toHaveBeenCalled();
137
- expect(delete_link.getAjaxType()).toEqual('DELETE')
138
- expect(delete_link.getAjaxUrl()).toEqual('/url')
139
- expect(delete_link.trigger).toEqual($link)
140
- })
141
- it("removes target after delete", function() {
142
- var $link = affix('a#test_dom_id[data-ajax-delete="true"][data-ajax-target="#test_dom_id"][href="/url"]');
143
- var data = "";
144
- var textStatus = "success";
145
- var jqXHR = new XMLHttpRequest();
146
- var delete_link = new thin_man.DeleteLink($link)
147
-
148
- delete_link.ajaxSuccess(data, textStatus, jqXHR)
149
-
150
- expect($('#test_dom_id').length).toEqual(0)
151
- })
152
- it("replaces response after target after delete", function() {
153
- var $div = affix('div#test_dom_id')
154
- var $link = $div.affix('a[data-ajax-delete="true"][data-ajax-target="#test_dom_id"][href="/url"]');
155
- var data = "I'm The Replacement Data";
156
- var textStatus = "success";
157
- var jqXHR = new XMLHttpRequest();
158
- var delete_link = new thin_man.DeleteLink($link)
159
-
160
- delete_link.ajaxSuccess(data, textStatus, jqXHR)
161
-
162
- expect($('#test_dom_id').html()).toEqual(data)
163
- })
164
- it("replaces response after target after delete and renders flash message", function() {
165
- var $div = affix('div#test_dom_id')
166
- var $link = $div.affix('a[data-ajax-delete="true"][data-ajax-target="#test_dom_id"][href="/url"]');
167
- var $flash = affix('div[data-thin-man-flash-template]');
168
- var $content = $flash.affix('div[data-thin-man-flash-content]')
169
-
170
- var data = { html: "I'm Barry Allen", flash_message: "I'm the flash" }
171
- var textStatus = "success";
172
- var jqXHR = { responseText: JSON.stringify(data) }
173
- var delete_link = new thin_man.DeleteLink($link)
174
-
175
- delete_link.ajaxSuccess(data, textStatus, jqXHR)
176
- delete_link.ajaxComplete(jqXHR)
177
-
178
- expect($('#test_dom_id').html()).toEqual(data.html)
179
- expect($('body').html()).toContain(data.flash_message)
180
- })
112
+
113
+ it("submits an ajax call with search params and path", function(){
114
+ var $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"][href="/url"][data-return-type="json"][data-search-params="search_params"][data-search-path="/search_path"]');
115
+ thin_man.AjaxLinkSubmission($link)
116
+ spyOn($, 'ajax');
117
+ $link.click();
118
+ expect($.ajax).toHaveBeenCalled();
119
+ expect(getAjaxArg("url")).toEqual('/search_path?search_params');
120
+ });
121
+
122
+ it("fires grouped links in sequence", function(){
123
+ var $link_zero = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="0"]');
124
+ var $link_one = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="1"]');
125
+ var $link_two = affix('a[data-ajax-link-now="true"][data-ajax-target="#test_dom_id"][href="/url"][data-ajax-method="PATCH"][data-sequence-group="test_group"][data-sequence-number="2"]');
126
+ zero = new thin_man.AjaxLinkSubmission($link_zero)
127
+ one = new thin_man.AjaxLinkSubmission($link_one)
128
+ two = new thin_man.AjaxLinkSubmission($link_two)
129
+ expect(thin_man.hasOwnProperty('link_groups')).toEqual(true)
130
+ spyOn(one,'fire')
131
+ spyOn(two,'fire')
132
+ zero.ajaxComplete()
133
+ expect(one.fire).toHaveBeenCalled();
134
+ expect(two.fire).not.toHaveBeenCalled();
135
+ one.ajaxComplete()
136
+ expect(one.fire.calls.count()).toEqual(1);
137
+ expect(two.fire).toHaveBeenCalled();
138
+ })
139
+ });
140
+ describe("DeleteLink", function(){
141
+ it("submits an ajax delete call with options", function(){
142
+ var $link = affix('a[data-ajax-delete="true"][data-ajax-target="#test_dom_id"][href="/url"]');
143
+ var delete_link = new thin_man.DeleteLink($link)
144
+ spyOn($, 'ajax');
145
+ $link.click();
146
+ expect($.ajax).toHaveBeenCalled();
147
+ expect(delete_link.getAjaxType()).toEqual('DELETE')
148
+ expect(delete_link.getAjaxUrl()).toEqual('/url')
149
+ expect(delete_link.trigger).toEqual($link)
150
+ })
151
+ });
152
+ describe("AjaxFormSubmission", function(){
153
+ it("submits an ajax call with options", function(){
154
+ var $form = affix('form[data-ajax-form="true"][method="PATCH"][action="/url"]');
155
+ $form.affix('input[type="text"][name="name"][value="Jon Snow"]')
156
+ thin_man.AjaxFormSubmission($form)
157
+ spyOn($, 'ajax');
158
+ $form.submit();
159
+ expect($.ajax).toHaveBeenCalled();
160
+ expect(getAjaxArg("url")).toMatch("/url");
161
+ expect(getAjaxArg("type")).toMatch("PATCH");
162
+ expect(getAjaxArg("datatype")).toMatch("html");
181
163
  });
182
- describe("AjaxFormSubmission", function() {
183
- it("submits an ajax call with options", function() {
184
- var $form = affix('form[data-ajax-form="true"][method="PATCH"][action="/url"]');
185
- $form.affix('input[type="text"][name="name"][value="Jon Snow"]')
186
- thin_man.AjaxFormSubmission($form)
187
- spyOn($, 'ajax');
188
- $form.submit();
189
- expect($.ajax).toHaveBeenCalled();
190
- expect(getAjaxArg("url")).toMatch("/url");
191
- expect(getAjaxArg("type")).toMatch("PATCH");
192
- expect(getAjaxArg("datatype")).toMatch("html");
193
- });
194
-
195
- describe("GET request", function() {
196
- var $form;
197
-
198
- beforeEach(function() {
199
- $form = affix('form[data-ajax-form="true"][action="/url"][method="GET"]');
200
- });
201
-
202
- it("serialize data", function() {
203
- $form.affix('input[type="text"][name="name"][value="Jon Snow"]');
204
- var thin = new thin_man.AjaxFormSubmission($form);
205
- spyOn($, 'ajax');
206
- $form.submit();
207
- expect($.ajax).toHaveBeenCalled();
208
- expect(thin.ajax_options.data).toEqual([{ name: 'name', value: 'Jon Snow' }, { name: 'thin_man_submitter', value: 'link_now' }]);
209
- });
210
-
211
- it(".getProcessData", function() {
212
- var thin = new thin_man.AjaxFormSubmission($form)
213
- expect(thin.getProcessData()).toBe(true);
214
- });
215
-
216
- it(".sendContentType", function() {
217
- var thin = new thin_man.AjaxFormSubmission($form)
218
- expect(thin.sendContentType()).toBe(true);
219
- });
220
- });
221
164
 
222
- describe("POST/PATCH/DELETE request", function() {
223
- var $form;
224
- beforeEach(function() {
225
- $form = affix('form[data-ajax-form="true"][action="/url"]');
226
- });
227
-
228
- it("Set data in a FormData object", function() {
229
- thin_man.AjaxFormSubmission($form)
230
- spyOn($, 'ajax');
231
- $form.submit();
232
- expect(getAjaxArg("data")).toEqual(jasmine.any(FormData));
233
- });
234
-
235
- it(".getProcessData", function() {
236
- var thin = new thin_man.AjaxFormSubmission($form)
237
- expect(thin.getProcessData()).toBe(false);
238
- });
239
-
240
- it(".sendContentType", function() {
241
- var thin = new thin_man.AjaxFormSubmission($form)
242
- expect(thin.sendContentType()).toBe(false);
243
- });
244
- });
165
+ describe("GET request", function(){
166
+ var $form;
167
+
168
+ beforeEach(function() {
169
+ $form = affix('form[data-ajax-form="true"][action="/url"][method="GET"]');
170
+ });
171
+
172
+ it("serialize data", function(){
173
+ $form.affix('input[type="text"][name="name"][value="Jon Snow"]');
174
+ var thin = new thin_man.AjaxFormSubmission($form);
175
+ spyOn($, 'ajax');
176
+ $form.submit();
177
+ expect($.ajax).toHaveBeenCalled();
178
+ expect(thin.ajax_options.data).toEqual([{ name: 'name', value: 'Jon Snow' },{name: 'thin_man_submitter', value: 'link_now'}]);
179
+ });
180
+
181
+ it(".getProcessData", function(){
182
+ var thin = new thin_man.AjaxFormSubmission($form)
183
+ expect(thin.getProcessData()).toBe(true);
184
+ });
185
+
186
+ it(".sendContentType", function(){
187
+ var thin = new thin_man.AjaxFormSubmission($form)
188
+ expect(thin.sendContentType()).toBe(true);
189
+ });
190
+ });
245
191
 
246
- describe("Log", function() {
247
- beforeEach(function() {
248
- spyOn(console, 'log');
249
- });
250
-
251
- it("Don't show a warning with a valid target", function() {
252
- $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
253
- $target = affix('#test_dom_id');
254
- thin = new thin_man.AjaxLinkSubmission($link);
255
- expect(console.log).not.toHaveBeenCalled();
256
- });
257
-
258
- it("Show a warning when target not found", function() {
259
- $link = affix('a[data-ajax-link="true"][data-ajax-target="#not_valid_target"]');
260
- thin = new thin_man.AjaxLinkSubmission($link);
261
- expect(console.log).toHaveBeenCalledWith('Warning! Thin Man selector #not_valid_target not found');
262
- });
263
-
264
- it("Show a warning when target not provided", function() {
265
- $link = affix('a[data-ajax-link="true"]');
266
- thin = new thin_man.AjaxLinkSubmission($link);
267
- expect(console.log).toHaveBeenCalledWith('Warning! Thin Man selector not given');
268
- });
269
- });
192
+ describe("POST/PATCH/DELETE request", function(){
193
+ var $form;
194
+ beforeEach(function(){
195
+ $form = affix('form[data-ajax-form="true"][action="/url"]');
196
+ });
197
+
198
+ it("Set data in a FormData object", function(){
199
+ thin_man.AjaxFormSubmission($form)
200
+ spyOn($, 'ajax');
201
+ $form.submit();
202
+ expect(getAjaxArg("data")).toEqual(jasmine.any(FormData));
203
+ });
204
+
205
+ it(".getProcessData", function(){
206
+ var thin = new thin_man.AjaxFormSubmission($form)
207
+ expect(thin.getProcessData()).toBe(false);
208
+ });
209
+
210
+ it(".sendContentType", function(){
211
+ var thin = new thin_man.AjaxFormSubmission($form)
212
+ expect(thin.sendContentType()).toBe(false);
213
+ });
214
+ });
270
215
 
216
+ describe("Log", function(){
217
+ beforeEach(function(){
218
+ spyOn(console, 'log');
219
+ });
220
+
221
+ it("Don't show a warning with a valid target", function(){
222
+ $link = affix('a[data-ajax-link="true"][data-ajax-target="#test_dom_id"]');
223
+ $target = affix('#test_dom_id');
224
+ thin = new thin_man.AjaxLinkSubmission($link);
225
+ expect(console.log).not.toHaveBeenCalled();
226
+ });
227
+
228
+ it("Show a warning when target not found", function(){
229
+ $link = affix('a[data-ajax-link="true"][data-ajax-target="#not_valid_target"]');
230
+ thin = new thin_man.AjaxLinkSubmission($link);
231
+ expect(console.log).toHaveBeenCalledWith('Warning! Thin Man selector #not_valid_target not found');
232
+ });
233
+
234
+ it("Show a warning when target not provided", function(){
235
+ $link = affix('a[data-ajax-link="true"]');
236
+ thin = new thin_man.AjaxLinkSubmission($link);
237
+ expect(console.log).toHaveBeenCalledWith('Warning! Thin Man selector not given');
238
+ });
271
239
  });
272
- });
240
+
241
+ });
242
+ });