sweet-alert-confirm 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79d4562caf3b1e3cecbf4c9d92fe3384d416c318
4
- data.tar.gz: 049049199569fe95b9594d134b4d6841e2795c89
3
+ metadata.gz: 062da72082efb99cea7919aa08d529cb8056033d
4
+ data.tar.gz: 8edd6e0c298c73abebafec9960d58b64f7791532
5
5
  SHA512:
6
- metadata.gz: 5c65648175a8152da2da0dacf0e08d1386a8926f13e7d2f90398025db361919065cc095f2698990fa51874e8234928f9d2a19ab818a46ccb26c3ef13b6f4cc68
7
- data.tar.gz: e6fc7263994d927fdd0b26b7f6f34a9b2face824aa12643f4bab822ba62c64801c7d22d39cc48a06d932ce3db48cb914a2b70eb4d05bb68dd9f65719c4e38e54
6
+ metadata.gz: c82c3281ade97c514d27985f2b70db34d5f26256a5c63a9b6ab1b1f166324824a2af0058b8d2ead039289f3246d028763da9fef996a793c2901fe56fc87c13b4
7
+ data.tar.gz: 3e1d5db6d9717d6d79ae7fbe0540f0452a454d78cbba3eeffb3384b191d1b7744d1acfec65f7161197d8341c52bea20dab64aa05f11fc5bf799cdd1ec437e98e
@@ -61,7 +61,7 @@
61
61
  if (r === false) {
62
62
  return false;
63
63
  } else {
64
- if($linkToVerify.is('input')){
64
+ if($linkToVerify.attr('type') == 'submit'){
65
65
  var name = $linkToVerify.attr('name'),
66
66
  data = name ? {name: name, value:$linkToVerify.val()} : null;
67
67
  $linkToVerify.closest('form').data('ujs:submit-button', data);
@@ -1,3 +1,3 @@
1
1
  module SweetAlertConfirm
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -15,6 +15,16 @@ module SweetAlertConfirm
15
15
  super value, options
16
16
  end
17
17
 
18
+ def button_tag(*args, &block)
19
+ html_options = args[block_given? ? 0 : 1] || {}
20
+
21
+ if options_has_confirm?(html_options)
22
+ html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) ||
23
+ html_options[:data].delete(:confirm)
24
+ end
25
+ super *args, &block
26
+ end
27
+
18
28
  protected
19
29
  def options_has_confirm?(options)
20
30
  if (options[:confirm] || (options[:data] && options[:data][:confirm]))
@@ -13,3 +13,7 @@
13
13
  <%= form_tag(delete_cow_path, method: :delete) do %>
14
14
  <%= submit_tag 'Submit to delete cow', id: 'submit-delete', data: {confirm: 'Are you sure?'} %>
15
15
  <% end %>
16
+
17
+ <%= form_tag(delete_cow_path, method: :delete) do %>
18
+ <%= button_tag('Button_tag confirm', id: 'button-confirm', data: { text: 'nanana', confirm: 'Are you sure?' }) %>
19
+ <% end %>
@@ -13,3 +13,7 @@
13
13
  <%= form_tag(delete_cow_path, method: :delete) do %>
14
14
  <%= submit_tag 'Submit to delete cow', id: 'submit-delete', data: {confirm: 'Are you sure?'} %>
15
15
  <% end %>
16
+
17
+ <%= form_tag(delete_cow_path, method: :delete) do %>
18
+ <%= button_tag('Button_tag confirm', id: 'button-confirm', data: { text: 'nanana', confirm: 'Are you sure?' }) %>
19
+ <% end %>
@@ -1,32 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'basic confirms', js: true, type: :feature do
4
- describe 'normal links' do
5
- before do
6
- visit confirms_page_path
7
- find_link("Basic confirm").trigger('click')
8
- end
9
4
 
10
- it 'doesnt follow the link when click', :js => true do
5
+ shared_examples 'Confirm shows correctly' do |is_cow_deleted, is_remote|
6
+ let(:got_cow) { 'You got a pretty cow' }
7
+ let(:deleted_cow) { 'You murdered a silly cow' }
8
+ let(:message) { is_cow_deleted ? deleted_cow : got_cow }
9
+
10
+ it 'doesnt follow the link when click' do
11
+ # require 'pry'
12
+ # binding.pry
11
13
  expect(page).to have_content('Are you sure?')
12
- expect(page).not_to have_content('You got a pretty cow')
14
+ expect(page).not_to have_content(message)
13
15
  end
14
16
 
15
17
  it 'dont follow the link when click on cancel' do
16
18
  sleep 1
17
- expect(page).to_not have_content('You got a pretty cow')
19
+ expect(page).to_not have_content(message)
18
20
  click_button('Cancel')
19
21
  sleep 1
20
- expect(page).to_not have_content('You got a pretty cow')
22
+ expect(page).to_not have_content(message)
21
23
  end
22
24
 
23
25
  it 'goes to the link after accept confirm' do
24
26
  #click_on '.confirm'
25
- expect(page).to_not have_content('You got a pretty cow')
27
+ expect(page).to_not have_content(message)
26
28
  sleep 1
27
29
  click_button('Ok')
28
- expect(page).to have_content('You got a pretty cow')
30
+ expect(page).to have_content(message)
31
+ end unless is_remote
32
+ end
33
+
34
+
35
+
36
+ describe 'normal links' do
37
+ before do
38
+ visit confirms_page_path
39
+ find_link("Basic confirm").trigger('click')
29
40
  end
41
+
42
+ it_behaves_like 'Confirm shows correctly'
30
43
  end
31
44
 
32
45
  describe 'methods links' do
@@ -35,27 +48,7 @@ describe 'basic confirms', js: true, type: :feature do
35
48
  find_link("Delete confirm").trigger('click')
36
49
  end
37
50
 
38
- it 'doesnt follow the link when click', :js => true do
39
- sleep 1
40
- expect(page).to have_content('Are you sure?')
41
- expect(page).not_to have_content('You murdered a silly cow')
42
- end
43
-
44
- it 'dont follow the link when click on cancel' do
45
- sleep 1
46
- expect(page).to_not have_content('You murdered a silly cow')
47
- click_button('Cancel')
48
- sleep 1
49
- expect(page).to_not have_content('You murdered a silly cow')
50
- end
51
-
52
- it 'goes to the link after accept confirm' do
53
- #click_on '.confirm'
54
- expect(page).to_not have_content('You murdered a silly cow')
55
- sleep 1
56
- click_button('Ok')
57
- expect(page).to have_content('You murdered a silly cow')
58
- end
51
+ it_behaves_like 'Confirm shows correctly', true
59
52
  end
60
53
 
61
54
  describe 'remote links' do
@@ -64,20 +57,7 @@ describe 'basic confirms', js: true, type: :feature do
64
57
  find_link("Remote confirm").trigger('click')
65
58
  end
66
59
 
67
- it 'doesnt follow the link when click', :js => true do
68
- sleep 1
69
- expect(page).to have_content('Are you sure?')
70
- expect(page).not_to have_content('You murdered a silly cow')
71
- end
72
-
73
- it 'doesnt follow the link when click on cancel' do
74
- sleep 1
75
- expect(page).to have_content('Are you sure?')
76
- expect(page).not_to have_content('You murdered a silly cow')
77
- click_button('Cancel')
78
- sleep 1
79
- expect(page).not_to have_content('You murdered a silly cow')
80
- end
60
+ it_behaves_like 'Confirm shows correctly', true, true
81
61
 
82
62
 
83
63
  it 'ajax change content in the page after accept confirm' do
@@ -110,28 +90,18 @@ describe 'basic confirms', js: true, type: :feature do
110
90
  visit confirms_page_path
111
91
  find("#submit-delete").trigger('click')
112
92
  end
113
- it 'show the alert when click the submit', :js => true do
114
- sleep 1
115
- expect(page).to have_content('Are you sure?')
116
- expect(page).not_to have_content('You murdered a silly cow')
117
- end
93
+ it_behaves_like 'Confirm shows correctly', true
94
+ end
118
95
 
119
- it 'does not submit the form when click on cancel' do
120
- sleep 1
121
- expect(page).to_not have_content('You murdered a silly cow')
122
- click_button('Cancel')
123
- sleep 1
124
- expect(page).to_not have_content('You murdered a silly cow')
96
+ describe 'button_tag links' do
97
+ before do
98
+ visit confirms_page_path
99
+ find_button("Button_tag confirm").trigger('click')
125
100
  end
126
101
 
127
- it 'submit the form after accept confirm' do
128
- #click_on '.confirm'
129
- expect(page).to_not have_content('You murdered a silly cow')
130
- sleep 1
131
- click_button('Ok')
132
- expect(page).to have_content('You murdered a silly cow')
133
- end
102
+ it_behaves_like 'Confirm shows correctly', true
134
103
  end
135
104
 
105
+
136
106
  end
137
107
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sweet-alert-confirm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moises Viloria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jquery-rails