dekiru 0.0.18 → 0.0.19

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: 2f97baa96504654fe776c451e96095e3aefceada
4
- data.tar.gz: fc7c0193f69f5973868908717b5dbadbcd4c489e
3
+ metadata.gz: 3f9b1e7e918814bcf4e4437eb398e239dc6af8da
4
+ data.tar.gz: c61905cf2a569b572bd2d712b0184ef0e1c1f74c
5
5
  SHA512:
6
- metadata.gz: 6c9e98a6fda416583fd5835d0e23747053362cdb499c68ad241bf2045a05a9bd376f657912a1ea8c5e5a7131c3369793f364cde56a154b005ff2adfce94e1af3
7
- data.tar.gz: 2dbba93f090592b4130180a6b4f1de2f9ffa2b93516a89df16c6cf9e46ec74f9c653a20c40bdb66e02f19811c784e216132c469269516ee17ad8f7b8c1a7288e
6
+ metadata.gz: 757e6e5d2fc1ecb642bcc8110a9be1980dc3014b1b1393934f784a243ebead80f46d1aacc439d694f775552b6a8d6da2f4c8fd81f4fa27f4abc10aa973b97ee3
7
+ data.tar.gz: 9a0c4a2a6ef0698adcb7c6e043e03a06b1eeda46c40dd0c3a72f49bd115ca9b5183fe0302843486846e479f47b486ddd5027eab3e10e18d1c8662a5297079611
@@ -1 +1 @@
1
- 2.2.4
1
+ 2.3.3
@@ -1,7 +1,6 @@
1
1
  rvm:
2
- - 2.0
3
- - 2.1
4
- - 2.2
2
+ - 2.2.6
3
+ - 2.3.3
5
4
 
6
5
  sudo: false
7
6
  cache: bundler
data/README.md CHANGED
@@ -50,6 +50,33 @@ task_with_monitor job: :environment, estimate_time: 10 do
50
50
  end
51
51
  ```
52
52
 
53
+ ## Capybara Helpers
54
+
55
+ 以下の設定をすると Capybara 用のヘルパーメソッドが使えるようになる。
56
+
57
+ ```ruby
58
+ require 'dekiru/capybara/helpers'
59
+ RSpec.configure do |config|
60
+ config.include Dekiru::Capybara::Helpers, type: :feature
61
+ end
62
+ ```
63
+
64
+ ### examples
65
+
66
+ ```ruby
67
+ # Ajax処理の終了待ち
68
+ click_link 'Ajax link!'
69
+ wait_for_ajax
70
+ expect(page).to have_content 'created element!'
71
+
72
+ # Bootstrap3 のモーダルの出現終了待ち(待たないとモーダル内のノードのクリックに失敗することがある)
73
+ wait_for_event('shown.bs.modal') do
74
+ click_link 'Open bootstrap3 modal'
75
+ end
76
+ click_on 'Button in modal'
77
+ ```
78
+
79
+
53
80
 
54
81
  ## Contributing
55
82
 
@@ -21,5 +21,6 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'faraday_middleware'
22
22
  gem.add_development_dependency 'rake', [">= 0"]
23
23
  gem.add_development_dependency 'rspec'
24
+ gem.add_development_dependency 'rubocop'
24
25
  gem.add_development_dependency 'webmock', ['>= 1.19.0']
25
26
  end
@@ -1,14 +1,12 @@
1
- require "dekiru/version"
2
- require "dekiru/railtie" if defined?(::Rails)
3
- require "dekiru/helper"
4
- require "dekiru/controller_additions"
1
+ require 'dekiru/version'
2
+ require 'dekiru/railtie' if defined?(::Rails)
3
+ require 'dekiru/helper'
4
+ require 'dekiru/controller_additions'
5
5
 
6
6
  require 'active_support'
7
7
  require 'active_support/all'
8
- require 'faraday'
9
- require 'faraday_middleware'
10
8
 
11
9
  module Dekiru
12
10
  end
13
11
 
14
- require_relative "dekiru/configure"
12
+ require_relative 'dekiru/configure'
@@ -0,0 +1,42 @@
1
+ module Dekiru
2
+ module Capybara
3
+ module Helpers
4
+ class Error < StandardError; end
5
+
6
+ def wait_for_event(event)
7
+ page.execute_script(<<~"EOS")
8
+ (function(){
9
+ var eventName = '#{event}';
10
+ window._dekiruCapybaraWaitEvents = window._dekiruCapybaraWaitEvents || {};
11
+ window._dekiruCapybaraWaitEvents[eventName] = 1;
12
+ jQuery(document).one(eventName, function(){window._dekiruCapybaraWaitEvents[eventName] = 0;});
13
+ })();
14
+ EOS
15
+ yield
16
+ Timeout.timeout(::Capybara.default_max_wait_time) do
17
+ script = <<~"EOS"
18
+ (function(){
19
+ var eventName = '#{event}';
20
+ return window._dekiruCapybaraWaitEvents && window._dekiruCapybaraWaitEvents[eventName];
21
+ })();
22
+ EOS
23
+ begin
24
+ result = page.evaluate_script(script)
25
+ raise Error, 'wait_for_event: Missing context. probably moved to another page.' if result.nil?
26
+ end while result == 1
27
+ end
28
+ end
29
+
30
+ # https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
31
+ def wait_for_ajax
32
+ Timeout.timeout(::Capybara.default_max_wait_time) do
33
+ loop until finished_all_ajax_requests?
34
+ end
35
+ end
36
+
37
+ def finished_all_ajax_requests?
38
+ page.evaluate_script('jQuery.active').zero?
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,4 +1,4 @@
1
- require "http_accept_language"
1
+ require 'http_accept_language'
2
2
 
3
3
  module Dekiru
4
4
  module ControllerAdditions
@@ -5,7 +5,7 @@ module Dekiru
5
5
  html_options, options, name = options, name, block if block_given?
6
6
 
7
7
  classes = html_options.try(:delete, :li_class).try(:split, ' ') || []
8
- classes << "active" if current_page?(options)
8
+ classes << 'active' if current_page?(options)
9
9
 
10
10
  obj = [options].flatten.last
11
11
  if obj.is_a?(ActiveRecord::Base)
@@ -25,7 +25,7 @@ module Dekiru
25
25
  alias nl null_check_localization
26
26
 
27
27
  def facebook_like(url = url_for(only_path: false), app_id = nil, width = 140)
28
- facebook_app_id = app_id || ENV["FACEBOOK_APP_ID"]
28
+ facebook_app_id = app_id || ENV['FACEBOOK_APP_ID']
29
29
  html = %Q(<iframe src="//www.facebook.com/plugins/like.php?href=#{u(url)}&amp;send=false&amp;layout=button_count&amp;width=140&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font=arial&amp;height=21&amp;appId=#{facebook_app_id}" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:#{width}px; height:21px;" allowTransparency="true"></iframe>)
30
30
  html.html_safe
31
31
  end
@@ -47,7 +47,7 @@ EOF
47
47
  end
48
48
 
49
49
  def google_analytics(code, options = {})
50
- if code.present? && ::Rails.env == "production"
50
+ if code.present? && ::Rails.env == 'production'
51
51
  multi_subdomain = if options[:domain]
52
52
  "_gaq.push(['_setDomainName', '#{options[:domain]}']);"
53
53
  end
@@ -0,0 +1,58 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ module Dekiru
5
+ class JobMonClient
6
+ def host
7
+ 'https://job-mon.herokuapp.com'
8
+ end
9
+
10
+ def conn
11
+ @conn ||= Faraday.new(:url => host) do |faraday|
12
+ faraday.request :url_encoded
13
+ faraday.request :json
14
+ faraday.response :json
15
+ faraday.adapter Faraday.default_adapter
16
+ end
17
+ end
18
+
19
+ def api_key
20
+ Dekiru.configure.monitor_api_key
21
+ end
22
+
23
+ def job_start(task, estimate_time, monitor_email)
24
+ body = {
25
+ job: {
26
+ name: task.name,
27
+ end_time: Time.current.since(estimate_time),
28
+ email: monitor_email
29
+ }
30
+ }
31
+ response = conn.post "/api/apps/#{api_key}/jobs.json", body
32
+ response.body['id']
33
+ rescue => e
34
+ Dekiru.configure.error_handle.call(e)
35
+ nil
36
+ end
37
+
38
+ def job_end(job_id)
39
+ if job_id
40
+ conn.put "/api/apps/#{api_key}/jobs/#{job_id}/finished.json"
41
+ end
42
+ end
43
+
44
+ def send_queue_log(count)
45
+ body = {
46
+ queue_log: {
47
+ count: count,
48
+ rails_env: Rails.env,
49
+ }
50
+ }
51
+ response = conn.post "/api/apps/#{api_key}/queue_logs.json", body
52
+ response.body['id']
53
+ rescue => e
54
+ Dekiru.configure.error_handle.call(e)
55
+ nil
56
+ end
57
+ end
58
+ end
@@ -11,8 +11,9 @@ module Dekiru
11
11
  end
12
12
 
13
13
  rake_tasks do
14
- load "dekiru/tasks/smtp_check.rake"
15
- load "dekiru/tasks/delayed_job_queue_check.rake"
14
+ load 'dekiru/tasks/smtp_check.rake'
15
+ load 'dekiru/tasks/delayed_job_queue_check.rake'
16
+ load 'dekiru/tasks/delayed_job_queue_monitor.rake'
16
17
  end
17
18
  end
18
19
  end
@@ -1,3 +1,5 @@
1
+ require 'dekiru/job_mon_client'
2
+
1
3
  module Dekiru
2
4
  module RakeMonitor
3
5
  def resolve_args(args)
@@ -5,50 +7,20 @@ module Dekiru
5
7
  [args, estimate_time]
6
8
  end
7
9
 
8
- def conn
9
- @conn ||= Faraday.new(:url => 'https://job-mon.herokuapp.com') do |faraday|
10
- faraday.request :url_encoded
11
- faraday.request :json
12
- faraday.response :json
13
- faraday.adapter Faraday.default_adapter
14
- end
15
- end
16
-
17
- def api_key
18
- Dekiru.configure.monitor_api_key
10
+ def client
11
+ @client ||= JobMonClient.new
19
12
  end
20
13
 
21
14
  def monitor_email
22
15
  Dekiru.configure.monitor_email
23
16
  end
24
17
 
25
- def job_start(task, estimate_time)
26
- body = {
27
- job: {
28
- name: task.name,
29
- end_time: Time.current.since(estimate_time),
30
- email: monitor_email
31
- }
32
- }
33
- response = conn.post "/api/apps/#{api_key}/jobs.json", body
34
- response.body["id"]
35
- rescue => e
36
- Dekiru.configure.error_handle.call(e)
37
- nil
38
- end
39
-
40
- def job_end(job_id)
41
- if job_id
42
- response = conn.put "/api/apps/#{api_key}/jobs/#{job_id}/finished.json", nil
43
- end
44
- end
45
-
46
18
  def task_with_monitor(*args, &block)
47
19
  args, estimate_time = resolve_args(args)
48
20
  task *args do |t|
49
- job_id = job_start(t, estimate_time)
21
+ job_id = client.job_start(t, estimate_time, monitor_email)
50
22
  block.call
51
- job_end(job_id)
23
+ client.job_end(job_id)
52
24
  end
53
25
  end
54
26
  end
@@ -10,7 +10,7 @@ module Dekiru
10
10
  Rails.logger.error "ENV['SMTP_CHECKER_TO_ADDR'] undefined!" if smtp_checker_to_addr.blank?
11
11
 
12
12
  Rails.logger.info "checkmail send start #{smtp_checker_to_addr} key:#{app_key}"
13
- subject = "[SMTP Checker] SMTP Check Mail"
13
+ subject = '[SMTP Checker] SMTP Check Mail'
14
14
  mail to: smtp_checker_to_addr, subject: subject do |format|
15
15
  format.text { render text: app_key }
16
16
  end
@@ -1,7 +1,8 @@
1
1
  namespace :dekiru do
2
- desc 'Ops check for Delayed::Job queue'
2
+ desc '[Deprecated] Ops check for Delayed::Job queue'
3
3
  task delayed_job_queue_check: :environment do
4
4
  Rails.logger.info "[INFO] Start dekiru:delayed_job_queue_check env:#{Rails.env}"
5
+ Rails.logger.warn '[WARNING] Use dekiru:delayed_job_queue_monitor'
5
6
  if defined?(Delayed::Job)
6
7
  if (count = Delayed::Job.where('run_at < ? or last_error IS NOT NULL', 30.seconds.since).count) > 0
7
8
  message = "There are #{count} jobs that are not running for Delayed::Job. Check job list!"
@@ -0,0 +1,13 @@
1
+ require 'dekiru/job_mon_client'
2
+
3
+ namespace :dekiru do
4
+ desc 'Ops monitor for Delayed::Job queue for job-mon'
5
+ task delayed_job_queue_monitor: :environment do
6
+ Rails.logger.info "[INFO] Start dekiru:delayed_job_queue_monitor env:#{Rails.env}"
7
+ if defined?(Delayed::Job)
8
+ count = Delayed::Job.where('run_at < ? or last_error IS NOT NULL', 30.seconds.since).count
9
+ Dekiru::JobMonClient.new.send_queue_log(count)
10
+ end
11
+ Rails.logger.info "[INFO] End dekiru:delayed_job_queue_monitor env:#{Rails.env}"
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Dekiru
2
- VERSION = "0.0.18"
2
+ VERSION = '0.0.19'
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require 'rails/generators'
2
- require 'faraday'
2
+ require 'dekiru/job_mon_client'
3
+
3
4
  class DekiruGenerator < Rails::Generators::Base
4
5
  source_root File.expand_path('../templates', __FILE__)
5
6
 
@@ -16,23 +17,18 @@ end
16
17
  end
17
18
  end
18
19
 
20
+ def client
21
+ @client ||= Dekiru::JobMonClient.new
22
+ end
23
+
19
24
  private
20
25
 
21
26
  def fetch_api_key
22
- res = api_conn.post '/api/apps.json', { app: { name: fetch_app_name } }
27
+ res = client.conn.post '/api/apps.json', app: { name: fetch_app_name }
23
28
  res.body['api_key']
24
29
  end
25
30
 
26
31
  def fetch_app_name
27
32
  File.basename(Rails.root)
28
33
  end
29
-
30
- def api_conn
31
- @conn ||= Faraday.new(url: 'https://job-mon.herokuapp.com') do |faraday|
32
- faraday.request :url_encoded
33
- faraday.request :json
34
- faraday.response :json
35
- faraday.adapter Faraday.default_adapter
36
- end
37
- end
38
- end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dekiru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Matsumura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-12 00:00:00.000000000 Z
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http_accept_language
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: webmock
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -124,13 +138,16 @@ files:
124
138
  - Rakefile
125
139
  - dekiru.gemspec
126
140
  - lib/dekiru.rb
141
+ - lib/dekiru/capybara/helpers.rb
127
142
  - lib/dekiru/configure.rb
128
143
  - lib/dekiru/controller_additions.rb
129
144
  - lib/dekiru/helper.rb
145
+ - lib/dekiru/job_mon_client.rb
130
146
  - lib/dekiru/railtie.rb
131
147
  - lib/dekiru/rake_monitor.rb
132
148
  - lib/dekiru/smtp_check_mailer.rb
133
149
  - lib/dekiru/tasks/delayed_job_queue_check.rake
150
+ - lib/dekiru/tasks/delayed_job_queue_monitor.rake
134
151
  - lib/dekiru/tasks/smtp_check.rake
135
152
  - lib/dekiru/version.rb
136
153
  - lib/generators/dekiru/dekiru_generator.rb
@@ -155,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
172
  version: '0'
156
173
  requirements: []
157
174
  rubyforge_project:
158
- rubygems_version: 2.4.5.1
175
+ rubygems_version: 2.5.2
159
176
  signing_key:
160
177
  specification_version: 4
161
178
  summary: Usefull helper methods for Ruby on Rails