message_train 0.4.6 → 0.5.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: d2c452b5241a4e611e157e797c7356978c9c5d42
4
- data.tar.gz: f1fe677ab65551e8df6edd6f717aad52dc7fd8e4
3
+ metadata.gz: cc19fc2e0a39e267e10c61fb9090fa72fd8bf7ae
4
+ data.tar.gz: b7f16af91e7cc61d8b050e1cf5c6bdfc8194c267
5
5
  SHA512:
6
- metadata.gz: 1ab0ee501281774dbb0386531283502776e84938039d1326a02dd199b15651d45ae216f601c328c72e672ee545fa491c4771874799124f4f70fe089be4686d03
7
- data.tar.gz: 6987c5bd65d63f30eb34de0cad9eec16793c4c07f6f7500ee8abbf1d9703f40f1b007bf34ee62e8d5fb39671ac981aa9b4a0934ee5ef3193ac87c336c1f2472a
6
+ metadata.gz: 63d3fb74b09bc2b5dee0bf57153fc1f35c82994541b4c2b2ba07ee09b85729f6c87b470cd6f81b7577ada84d9534d5c24a8b3c22adcf8792daca7cc7fee17c9e
7
+ data.tar.gz: 0438d2ca2ecd8f450626642ac0dfb9fa848c6cd3d3f4a7c16ba39fca5c5112fad0b650e547dddc8e46f8a8609c3d96b2641b3bff80117128d1969fc0b18a4318
data/Gemfile CHANGED
@@ -9,6 +9,9 @@ gem 'haml-rails', '~> 0.9'
9
9
  gem 'jquery-rails', '~> 4'
10
10
  gem 'uglifier', '~> 2.7'
11
11
 
12
+ # Use CoffeeScript for .coffee assets and views
13
+ gem 'coffee-rails', '~> 4.1.0'
14
+
12
15
  # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
13
16
  gem 'jbuilder', '~> 2.0'
14
17
 
@@ -17,8 +20,11 @@ gem 'bootstrap-sass', '~> 3.3'
17
20
  gem 'bootstrap_leather', '~> 0.8'
18
21
  gem 'bootstrap_pager', '~> 0.10'
19
22
  gem 'bootstrap_form', '~> 2.3'
20
- gem 'bootstrap-wysihtml5-rails', '~> 0.3'
23
+ gem 'ckeditor'
24
+ gem 'bootstrap_tokenfield_rails', '~> 0.12'
21
25
  gem 'cocoon', '~> 1.2'
26
+ gem 'jquery-ui-bootstrap-rails-asset'
27
+ gem 'twitter-typeahead-rails'
22
28
 
23
29
  # Add dependencies to develop your gem here.
24
30
  # Include everything needed to run rake, tests, features, etc.
data/README.rdoc CHANGED
@@ -15,7 +15,7 @@ Email messages are sent when a user receives a message, either directly or throu
15
15
  == Installation
16
16
 
17
17
  First, install the gem:
18
- gem 'bootstrap-wysihtml5-rails'
18
+ gem 'ckeditor'
19
19
  gem 'message_train'
20
20
 
21
21
  Then, run the install generator:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.6
1
+ 0.5.0
@@ -0,0 +1,48 @@
1
+ CKEDITOR.editorConfig = (config) ->
2
+ config.allowedContent = true
3
+ config.width = '100%'
4
+ config.toolbar_full = [
5
+ {
6
+ name: 'links',
7
+ items: [
8
+ 'Link',
9
+ 'Unlink'
10
+ ]
11
+ },
12
+ {
13
+ name: 'paragraph',
14
+ groups: [
15
+ 'list',
16
+ 'indent',
17
+ 'blocks',
18
+ 'align',
19
+ 'bidi'
20
+ ],
21
+ items: [
22
+ 'NumberedList',
23
+ 'BulletedList',
24
+ '-',
25
+ 'Outdent',
26
+ 'Indent',
27
+ '-',
28
+ 'Blockquote'
29
+ ]
30
+ },
31
+ {
32
+ name: 'basicstyles',
33
+ groups: [
34
+ 'basicstyles',
35
+ 'cleanup'
36
+ ],
37
+ items: [
38
+ 'Format',
39
+ 'Bold',
40
+ 'Italic',
41
+ 'Strike',
42
+ '-',
43
+ 'RemoveFormat'
44
+ ]
45
+ }
46
+ ]
47
+ config.toolbar = 'full'
48
+ true
@@ -1,6 +1,7 @@
1
- //= require bootstrap-tags
1
+ //= require twitter/typeahead.min
2
+ //= require bootstrap-tokenfield
2
3
  //= require cocoon
3
- //= require bootstrap-wysihtml5
4
+ //= require ckeditor/init
4
5
 
5
6
  function create_alert(level, message) {
6
7
  $('#alert_area').append('<div class="alert alert-' + level + ' alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' + message + ' </div>');
@@ -61,31 +62,17 @@ function process_results(data) {
61
62
  }
62
63
 
63
64
  function add_tag_magic(selector) {
64
- var div = $(selector);
65
- var model = div.data('model');
66
- if ( div.data('read-only') ) {
67
- var readOnly = true;
68
- } else {
69
- var readOnly = false;
70
- }
71
- var request_string = '/box/in/participants/' + model + '.json';
72
- $.getJSON(request_string, function(data){
73
- var form = div.parents('form');
74
- var suggestions = [];
75
- $.each(data.participants, function (i, participant) {
76
- suggestions.push(participant.slug);
77
- });
78
- var tags = div.tags({
79
- readOnly: readOnly,
80
- suggestions: suggestions,
81
- tagSize: 'lg',
82
- promptText: 'Comma separated list'
83
- });
84
- form.submit(function(e) {
85
- field_template = '<input name="' + div.data('field-name') + '" value="' + tags.getTags() + '" type="hidden">';
86
- form.append(field_template);
87
- return true;
88
- });
65
+ $(selector).tokenfield({
66
+ typeahead: [
67
+ {
68
+ hint: true,
69
+ highlight: true
70
+ },
71
+ {
72
+ source: suggestions.ttAdapter()
73
+ }
74
+ ],
75
+ showAutocompleteOnFocus: true
89
76
  });
90
77
  }
91
78
 
@@ -100,6 +87,7 @@ $(document).ready(function(){
100
87
  $(this).parents('.message_train_conversation').removeClass('selected');
101
88
  }
102
89
  });
90
+
103
91
  $('#check_all').change(function(event) {
104
92
  if (event.target.checked) {
105
93
  set_and_change( '.message_train_conversation input[type="checkbox"]', true);
@@ -107,6 +95,7 @@ $(document).ready(function(){
107
95
  set_and_change( '.message_train_conversation input[type="checkbox"]', false);
108
96
  }
109
97
  });
98
+
110
99
  $('#box-actions .check').click(function(event) {
111
100
  event.preventDefault();
112
101
  selector = $(this).data('selector');
@@ -120,6 +109,7 @@ $(document).ready(function(){
120
109
  set_and_change( selector + ' input[type="checkbox"]', true);
121
110
  }
122
111
  });
112
+
123
113
  $('#box-actions .mark').click(function(event) {
124
114
  event.preventDefault();
125
115
  $('#spinner').removeClass('hide');
@@ -132,13 +122,14 @@ $(document).ready(function(){
132
122
  $('input[name="mark_to_set"]').val(mark_to_set);
133
123
  $('#box').submit();
134
124
  });
135
- $('#box')
136
- .on('ajax:success', function (e, data, status, xhr) {
137
- $('#spinner').addClass('hide');
138
- process_results(data);
139
- }).on('ajax:error', function (e, data, status, xhr) {
140
- create_alert('danger', data.responseJSON.message);
141
- });
125
+
126
+ $('#box').on('ajax:success', function (e, data, status, xhr) {
127
+ $('#spinner').addClass('hide');
128
+ process_results(data);
129
+ }).on('ajax:error', function (e, data, status, xhr) {
130
+ create_alert('danger', data.responseJSON.message);
131
+ });
132
+
142
133
  $('#box #message_train_messages .read').each(function(e){
143
134
  $(this).find('.collapse').collapse('hide');
144
135
  });
@@ -154,21 +145,5 @@ $(document).ready(function(){
154
145
  var text = button.data('text');
155
146
  var modal = $(this);
156
147
  modal.find('#image_placeholder').html('<a href="' + original + '" title="' + text + '"><img src="' + src + '" /></a>')
157
- })
158
-
159
- $('.wysiwyg').wysihtml5({
160
- toolbar: {
161
- 'font-styles': true,
162
- 'color': false,
163
- 'emphasis': {
164
- 'small': true
165
- },
166
- 'blockquote': true,
167
- 'lists': true,
168
- 'html': false,
169
- 'link': true,
170
- 'image': false,
171
- 'smallmodals': true
172
- }
173
148
  });
174
149
  });
@@ -1,5 +1,5 @@
1
- @import 'bootstrap-tags';
2
- @import "bootstrap-wysihtml5/bootstrap3-wysihtml5";
1
+ @import 'tokenfield-typeahead';
2
+ @import 'bootstrap-tokenfield';
3
3
 
4
4
  img {
5
5
  max-width: 100%;
@@ -123,9 +123,10 @@ tr:hover .conversation-actions a {
123
123
  white-space: inherit;
124
124
  }
125
125
 
126
- .tags-input {
127
- border-radius: 4px;
128
- padding-left: 12px;
126
+ .tt-menu {
127
+ @extend .tt-dropdown-menu;
128
+ border-top-left-radius: 0;
129
+ border-top-right-radius: 0;
129
130
  }
130
131
 
131
132
  .dropdown-menu {
@@ -71,7 +71,7 @@ module MessageTrain
71
71
  )
72
72
  if permitted['draft'] == :save_as_draft.l
73
73
  permitted['draft'] = true
74
- elsif permitted['draft'] == :send.l
74
+ else
75
75
  permitted['draft'] = false
76
76
  end
77
77
  permitted
@@ -35,6 +35,10 @@ module MessageTrain
35
35
  else
36
36
  @participants = model.all
37
37
  end
38
+ if params[:query].present?
39
+ field_name = MessageTrain.configuration.slug_columns[model_sym]
40
+ @participants = @participants.where("#{field_name} LIKE ?", "#{params[:query]}%")
41
+ end
38
42
  end
39
43
 
40
44
  def load_participant
@@ -4,11 +4,32 @@
4
4
  - resource = message.new_record? ? message_train.collective_box_messages_path(@collective.path_part, @box) : message_train.collective_box_message_path(@collective.path_part, @box, message)
5
5
  = bootstrap_form_for message, url: resource do |f|
6
6
  - if @collective.nil?
7
- = render partial: 'message_train/participants/field', locals: { message: message, field_name: :users }
7
+ = f.fields_for :recipients_to_save do |g|
8
+ = g.text_field :users, label: :recipients.l, class: 'recipient-input'
9
+ - add_footer_javascript do
10
+ :javascript
11
+ url = "/box/in/participants/users.json"
12
+ var suggestions = new Bloodhound({
13
+ prefetch: url,
14
+ remote: {
15
+ wildcard: '%QUERY',
16
+ url: url + '?query=%QUERY',
17
+ transform: function(response) {
18
+ return $.map(response.participants, function(val, i) {
19
+ return val.slug
20
+ });
21
+ }
22
+ },
23
+ queryTokenizer: Bloodhound.tokenizers.whitespace,
24
+ datumTokenizer: function(item) {
25
+ return Bloodhound.tokenizers.whitespace(item.slug);
26
+ }
27
+ });
8
28
  - else
9
29
  = render partial: 'message_train/participants/prefilled_field', locals: { message: message, recipient: @collective }
10
30
  = f.text_field :subject
11
- = f.text_area :body, class: 'wysiwyg'
31
+ = f.form_group :body, label: { text: MessageTrain::Message.human_attribute_name(:body) } do
32
+ = f.cktext_area :body
12
33
  .links
13
34
  %h3
14
35
  = link_to_add_association(icon('plus'), f, :attachments, title: :add_attachment.l, class: 'btn btn-info', id: 'add-attachment', data: { association_insertion_method: 'append', association_insertion_node: '#attachments'})
@@ -16,5 +37,5 @@
16
37
  #attachments
17
38
  = f.fields_for :attachments do |attachment|
18
39
  = render 'attachment_fields', f: attachment
19
- = f.submit :save_as_draft.l, name: 'message[draft]'
20
- = f.submit :send.l, class: 'btn btn-primary', name: 'message[draft]'
40
+ = f.submit :save_as_draft.l, name: 'message[draft]', id: 'save-as-draft'
41
+ = f.submit :send.l, class: 'btn btn-primary', name: 'message[draft]', id: 'send'
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: message_train 0.4.6 ruby lib
5
+ # stub: message_train 0.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "message_train"
9
- s.version = "0.4.6"
9
+ s.version = "0.5.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Karen Lundgren"]
14
- s.date = "2016-02-19"
14
+ s.date = "2016-02-20"
15
15
  s.description = "Rails 4 Engine providing private/public messaging for any object, such as Users or Groups"
16
16
  s.email = "karen.e.lundgren@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "README.rdoc",
31
31
  "Rakefile",
32
32
  "VERSION",
33
+ "app/assets/javascripts/ckeditor/config.js.coffee",
33
34
  "app/assets/javascripts/message_train.js",
34
35
  "app/assets/stylesheets/message_train.scss",
35
36
  "app/controllers/concerns/message_train_support.rb",
@@ -86,7 +87,6 @@ Gem::Specification.new do |s|
86
87
  "app/views/message_train/messages/edit.html.haml",
87
88
  "app/views/message_train/messages/new.html.haml",
88
89
  "app/views/message_train/messages/show.json.jbuilder",
89
- "app/views/message_train/participants/_field.html.haml",
90
90
  "app/views/message_train/participants/_participant.json.jbuilder",
91
91
  "app/views/message_train/participants/_prefilled_field.html.haml",
92
92
  "app/views/message_train/participants/index.json.jbuilder",
@@ -270,10 +270,7 @@ Gem::Specification.new do |s|
270
270
  "spec/support/roles.rb",
271
271
  "spec/support/shared_connection.rb",
272
272
  "spec/support/users.rb",
273
- "spec/support/utilities.rb",
274
- "spec/support/wysihtml5_helper.rb",
275
- "vendor/assets/javascripts/bootstrap-tags.js",
276
- "vendor/assets/stylesheets/bootstrap-tags.css"
273
+ "spec/support/utilities.rb"
277
274
  ]
278
275
  s.homepage = "http://www.gemvein.com/museum/cases/message_train"
279
276
  s.licenses = ["MIT"]
@@ -290,14 +287,18 @@ Gem::Specification.new do |s|
290
287
  s.add_runtime_dependency(%q<haml-rails>, ["~> 0.9"])
291
288
  s.add_runtime_dependency(%q<jquery-rails>, ["~> 4"])
292
289
  s.add_runtime_dependency(%q<uglifier>, ["~> 2.7"])
290
+ s.add_runtime_dependency(%q<coffee-rails>, ["~> 4.1.0"])
293
291
  s.add_runtime_dependency(%q<jbuilder>, ["~> 2.0"])
294
292
  s.add_runtime_dependency(%q<sass-rails>, ["~> 5"])
295
293
  s.add_runtime_dependency(%q<bootstrap-sass>, ["~> 3.3"])
296
294
  s.add_runtime_dependency(%q<bootstrap_leather>, ["~> 0.8"])
297
295
  s.add_runtime_dependency(%q<bootstrap_pager>, ["~> 0.10"])
298
296
  s.add_runtime_dependency(%q<bootstrap_form>, ["~> 2.3"])
299
- s.add_runtime_dependency(%q<bootstrap-wysihtml5-rails>, ["~> 0.3"])
297
+ s.add_runtime_dependency(%q<ckeditor>, [">= 0"])
298
+ s.add_runtime_dependency(%q<bootstrap_tokenfield_rails>, ["~> 0.12"])
300
299
  s.add_runtime_dependency(%q<cocoon>, ["~> 1.2"])
300
+ s.add_runtime_dependency(%q<jquery-ui-bootstrap-rails-asset>, [">= 0"])
301
+ s.add_runtime_dependency(%q<twitter-typeahead-rails>, [">= 0"])
301
302
  s.add_development_dependency(%q<sdoc>, ["~> 0.4.1"])
302
303
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
303
304
  s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
@@ -319,14 +320,18 @@ Gem::Specification.new do |s|
319
320
  s.add_dependency(%q<haml-rails>, ["~> 0.9"])
320
321
  s.add_dependency(%q<jquery-rails>, ["~> 4"])
321
322
  s.add_dependency(%q<uglifier>, ["~> 2.7"])
323
+ s.add_dependency(%q<coffee-rails>, ["~> 4.1.0"])
322
324
  s.add_dependency(%q<jbuilder>, ["~> 2.0"])
323
325
  s.add_dependency(%q<sass-rails>, ["~> 5"])
324
326
  s.add_dependency(%q<bootstrap-sass>, ["~> 3.3"])
325
327
  s.add_dependency(%q<bootstrap_leather>, ["~> 0.8"])
326
328
  s.add_dependency(%q<bootstrap_pager>, ["~> 0.10"])
327
329
  s.add_dependency(%q<bootstrap_form>, ["~> 2.3"])
328
- s.add_dependency(%q<bootstrap-wysihtml5-rails>, ["~> 0.3"])
330
+ s.add_dependency(%q<ckeditor>, [">= 0"])
331
+ s.add_dependency(%q<bootstrap_tokenfield_rails>, ["~> 0.12"])
329
332
  s.add_dependency(%q<cocoon>, ["~> 1.2"])
333
+ s.add_dependency(%q<jquery-ui-bootstrap-rails-asset>, [">= 0"])
334
+ s.add_dependency(%q<twitter-typeahead-rails>, [">= 0"])
330
335
  s.add_dependency(%q<sdoc>, ["~> 0.4.1"])
331
336
  s.add_dependency(%q<bundler>, ["~> 1.0"])
332
337
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
@@ -349,14 +354,18 @@ Gem::Specification.new do |s|
349
354
  s.add_dependency(%q<haml-rails>, ["~> 0.9"])
350
355
  s.add_dependency(%q<jquery-rails>, ["~> 4"])
351
356
  s.add_dependency(%q<uglifier>, ["~> 2.7"])
357
+ s.add_dependency(%q<coffee-rails>, ["~> 4.1.0"])
352
358
  s.add_dependency(%q<jbuilder>, ["~> 2.0"])
353
359
  s.add_dependency(%q<sass-rails>, ["~> 5"])
354
360
  s.add_dependency(%q<bootstrap-sass>, ["~> 3.3"])
355
361
  s.add_dependency(%q<bootstrap_leather>, ["~> 0.8"])
356
362
  s.add_dependency(%q<bootstrap_pager>, ["~> 0.10"])
357
363
  s.add_dependency(%q<bootstrap_form>, ["~> 2.3"])
358
- s.add_dependency(%q<bootstrap-wysihtml5-rails>, ["~> 0.3"])
364
+ s.add_dependency(%q<ckeditor>, [">= 0"])
365
+ s.add_dependency(%q<bootstrap_tokenfield_rails>, ["~> 0.12"])
359
366
  s.add_dependency(%q<cocoon>, ["~> 1.2"])
367
+ s.add_dependency(%q<jquery-ui-bootstrap-rails-asset>, [">= 0"])
368
+ s.add_dependency(%q<twitter-typeahead-rails>, [">= 0"])
360
369
  s.add_dependency(%q<sdoc>, ["~> 0.4.1"])
361
370
  s.add_dependency(%q<bundler>, ["~> 1.0"])
362
371
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
Binary file
@@ -1,7 +1,6 @@
1
1
  require 'rails_helper'
2
2
  RSpec.feature 'Messages' do
3
3
  include_context 'loaded site'
4
- include Wysihtml5Helper
5
4
 
6
5
  it_behaves_like 'an authenticated section', '/box/in/messages/new'
7
6
 
@@ -13,11 +12,10 @@ RSpec.feature 'Messages' do
13
12
  describe 'at /box/in/messages' do
14
13
  before do
15
14
  visit '/box/in/messages/new/'
16
- recipient_input = find(:css, "#message_recipients_to_save_users .tags-input")
17
- recipient_input.set("")
15
+ fill_in_autocomplete 'Recipients', with: 'x'
18
16
  fill_in 'Subject', with: 'This is a draft.'
19
- fill_in_html 'Body', with: 'This is the body.'
20
- click_button 'Send'
17
+ fill_in_ckeditor 'Body', with: 'This is the body.'
18
+ submit_via_button 'Send'
21
19
  end
22
20
  it_behaves_like 'a bootstrap page with an alert', 'warning', 'Message saved as draft.'
23
21
  end
@@ -26,12 +24,9 @@ RSpec.feature 'Messages' do
26
24
  describe 'at /box/in/messages' do
27
25
  before do
28
26
  visit '/box/in/messages/new/'
29
- recipient_input = find(:css, "#message_recipients_to_save_users .tags-input")
30
- recipient_input.set("sec") # Should auto-complete to second-user with the following two key-presses
31
- recipient_input.native.send_keys :arrow_down
32
- recipient_input.native.send_keys :return
27
+ fill_in_autocomplete 'Recipients', with: 'sec'
33
28
  fill_in 'Subject', with: 'This is the subject.'
34
- fill_in_html 'Body', with: 'This is the body.'
29
+ fill_in_ckeditor 'Body', with: 'This is the body.'
35
30
  click_link 'add-attachment'
36
31
  click_link 'add-attachment'
37
32
  click_link 'add-attachment'
@@ -46,7 +41,7 @@ RSpec.feature 'Messages' do
46
41
  find('.remove_fields').click
47
42
  end
48
43
  end
49
- click_button 'Send'
44
+ submit_via_button 'Send'
50
45
  end
51
46
  it_behaves_like 'a bootstrap page with an alert', 'info', 'Message sent.'
52
47
  end
@@ -55,13 +50,10 @@ RSpec.feature 'Messages' do
55
50
  describe 'at /box/in/messages' do
56
51
  before do
57
52
  visit "/box/in/conversations/#{draft_conversation.id}"
58
- recipient_input = find(:css, "#message_recipients_to_save_users .tags-input")
59
- recipient_input.set("sec") # Should auto-complete to second-user with the following two key-presses
60
- recipient_input.native.send_keys :arrow_down
61
- recipient_input.native.send_keys :return
53
+ fill_in_autocomplete 'Recipients', with: 'sec'
62
54
  fill_in 'Subject', with: 'This is the subject.'
63
- fill_in_html 'Body', with: 'This is the body.'
64
- click_button 'Send'
55
+ fill_in_ckeditor 'Body', with: 'This is the body.'
56
+ submit_via_button 'Send'
65
57
  end
66
58
  it_behaves_like 'a bootstrap page with an alert', 'info', 'Message sent.'
67
59
  it_behaves_like 'a bootstrap page without an alert', 'warning'
@@ -1,4 +1,3 @@
1
- # In your test_helper.rb
2
1
  class ActiveRecord::Base
3
2
  mattr_accessor :shared_connection
4
3
  @@shared_connection = nil
@@ -5,4 +5,55 @@ end
5
5
  def show_page
6
6
  save_page Rails.root.join( 'public', 'capybara.html' )
7
7
  %x(launchy http://localhost:3000/capybara.html)
8
+ end
9
+
10
+ def submit_via_button(button_name)
11
+ button_id = find("input[type=submit][value='#{button_name}']")[:id]
12
+ page.execute_script("$('##{button_id}').click();")
13
+ end
14
+
15
+ # Used to fill ckeditor fields
16
+ # @param [String] locator label text for the textarea or textarea id
17
+ def fill_in_ckeditor(locator, options)
18
+ locator = find_field_by_label(locator)
19
+ # Fill the editor content
20
+ page.execute_script <<-SCRIPT
21
+ var ckeditor = CKEDITOR.instances.#{locator}
22
+ ckeditor.setData('#{ActionController::Base.helpers.j options[:with]}')
23
+ ckeditor.focus()
24
+ ckeditor.updateElement()
25
+ SCRIPT
26
+ end
27
+
28
+ def fill_in_autocomplete(field, options = {})
29
+ field = find_field_by_label(field)
30
+ fill_in field, with: options[:with]
31
+
32
+ page.execute_script %Q{ $('##{field}').trigger('focus') }
33
+ page.execute_script %Q{ $('##{field}').trigger('keydown') }
34
+ selector = %Q{.tt-menu .tt-suggestion:contains("#{options[:with]}")}
35
+
36
+ if page.has_selector?('.tt-menu .tt-suggestion')
37
+ page.execute_script %Q{ $('#{selector}').trigger('mouseenter').click() }
38
+ end
39
+ end
40
+
41
+ def find_field_by_label(locator)
42
+ if page.has_css?('label', text: locator)
43
+ find('label', text: locator)[:for]
44
+ else
45
+ locator
46
+ end
47
+ end
48
+
49
+ def wait_until(delay = 1)
50
+ seconds_waited = 0
51
+ while !yield && seconds_waited < Capybara.default_max_wait_time
52
+ sleep delay
53
+ seconds_waited += 1
54
+ end
55
+ unless yield
56
+ puts "Waited for #{Capybara.default_max_wait_time} seconds."
57
+ puts "{#{yield}} did not become true, continuing."
58
+ end
8
59
  end