dekiru 0.1.0 → 0.1.1

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
- SHA1:
3
- metadata.gz: 494f40b2837d03839b7d9602f7bcd3f3c0d47196
4
- data.tar.gz: 70aff4c1bbba2c7c600233735954e72954105b5f
2
+ SHA256:
3
+ metadata.gz: b715602bf9f53b9d6abba728f17c8bdc2b295e96127c7a0623045801f9a11e0c
4
+ data.tar.gz: 3cf3fa34a75e486df3db5bbeb882f1de6172624bd1f4e06d6acf55d12339b5df
5
5
  SHA512:
6
- metadata.gz: 0e41ca1c9e1f95eaf56f1a16af2fde9f7b4af77d8e47db9cd2d9539df1ffee34317a58734429e4a443b470524f59f7776883af4396185ada670d73743f725035
7
- data.tar.gz: d2281d2ccaac6a60f9ce1db85fe47dd097b84f6af635836ee40c8d8af05c8cd0d684e26447a31e82e3a6f0adf7d1c9f448ead2565365cf0076902007d2e582fc
6
+ metadata.gz: 1b4a8bf6efb8052718f21e4d29495f9e6149c0681fe64a15c234801d4e0a4036c697ecb27c2a7b73757f7f3f8624191390b7d2b1341ac6d6f0fc3b7b3d110710
7
+ data.tar.gz: 654d3c85c7a65deb7af1bdb243e716d49ecb77e8bb710d0e5b8bfabf94d65ed0e7670c3e012879358c9267db8e79cb4f8a1e9f63c8681af73864595d387b9100
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.5.1
@@ -1,6 +1,11 @@
1
1
  rvm:
2
- - 2.2.6
3
2
  - 2.3.3
3
+ - 2.4.4
4
+ - 2.5.1
5
+
6
+ # NOTE: https://github.com/travis-ci/travis-ci/issues/8978
7
+ before_install:
8
+ - gem update --system --no-document
4
9
 
5
10
  sudo: false
6
11
  cache: bundler
data/README.md CHANGED
@@ -48,6 +48,42 @@ end
48
48
  click_on 'Button in modal'
49
49
  ```
50
50
 
51
+ ## Rake Task
52
+
53
+ 以下の設定をすると Rake タスクの実行前後にログ出力されるようになる。(Ruby2.4 以降が必要)
54
+
55
+ In Rakefile:
56
+
57
+ ```ruby
58
+ require_relative 'config/application'
59
+ require 'dekiru/task_with_logger'
60
+
61
+ Rails.application.load_tasks
62
+ ```
63
+
64
+ In myapp.rake:
65
+
66
+ ```ruby
67
+ using TaskWithLogger
68
+
69
+ namespace :myapp do
70
+ desc 'dekiru'
71
+ task dekiru: :environment do
72
+ puts 'dekiru'
73
+ end
74
+ end
75
+ ```
76
+
77
+ 以下の設定をすると db:migrate タスクの実行前に競合がチェックされる。
78
+
79
+ In Rakefile:
80
+
81
+ ```ruby
82
+ require_relative 'config/application'
83
+
84
+ Rails.application.load_tasks
85
+ Rake::Task['db:migrate'].enhance(['db:migrate:check_confrict']) if Rails.env.development?
86
+ ```
51
87
 
52
88
  ## Contributing
53
89
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env rake
2
- require "bundler/gem_tasks"
2
+ require 'bundler/gem_tasks'
3
3
  require 'rspec/core/rake_task'
4
4
 
5
5
  task :default => :spec
@@ -2,6 +2,7 @@ require 'dekiru/version'
2
2
  require 'dekiru/railtie' if defined?(::Rails)
3
3
  require 'dekiru/helper'
4
4
  require 'dekiru/controller_additions'
5
+ require 'dekiru/validators/existence'
5
6
 
6
7
  require 'active_support'
7
8
  require 'active_support/all'
@@ -13,30 +13,38 @@ module Dekiru
13
13
  })();
14
14
  EOS
15
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
16
+
17
+ script = <<~"EOS"
18
+ (function(){
19
+ var eventName = '#{event}';
20
+ return window._dekiruCapybaraWaitEvents && window._dekiruCapybaraWaitEvents[eventName];
21
+ })();
22
+ EOS
23
+ wait_until do
24
+ result = page.evaluate_script(script)
25
+ raise Error, 'wait_for_event: Missing context. probably moved to another page.' if result.nil?
26
+ result == 0
27
27
  end
28
28
  end
29
29
 
30
30
  # https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
31
31
  def wait_for_ajax
32
- Timeout.timeout(::Capybara.default_max_wait_time) do
33
- loop until finished_all_ajax_requests?
34
- end
32
+ wait_until { finished_all_ajax_requests? }
35
33
  end
36
34
 
37
35
  def finished_all_ajax_requests?
38
36
  page.evaluate_script('jQuery.active').zero?
39
37
  end
38
+
39
+ def wait_until(timeout: ::Capybara.default_max_wait_time, interval: 0.2, **opts, &block)
40
+ if defined?(Selenium::WebDriver::Wait)
41
+ Selenium::WebDriver::Wait.new(opts.merge(timeout: timeout, interval: interval)).until { yield }
42
+ else
43
+ Timeout.timeout(timeout) do
44
+ sleep(interval) until yield
45
+ end
46
+ end
47
+ end
40
48
  end
41
49
  end
42
50
  end
@@ -12,6 +12,7 @@ module Dekiru
12
12
 
13
13
  rake_tasks do
14
14
  load 'dekiru/tasks/smtp_check.rake'
15
+ load 'dekiru/tasks/db.rake'
15
16
  end
16
17
  end
17
18
  end
@@ -0,0 +1,20 @@
1
+ module TaskWithLogger
2
+ refine Rake::DSL do
3
+ private
4
+
5
+ def task(*args, &block)
6
+ scope_path = Rake.application.current_scope.path
7
+ new_block = proc do
8
+ __echo__ "[START] #{scope_path}: #{args.inspect} (#{Time.current})"
9
+ yield
10
+ __echo__ "[END] #{scope_path}: #{args.inspect} (#{Time.current})"
11
+ end
12
+ super(*args, &new_block)
13
+ end
14
+
15
+ def __echo__(str)
16
+ Rails.logger.info(str)
17
+ puts(str)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ namespace :db do
2
+ namespace :migrate do
3
+ desc 'Check migrate confrict'
4
+ task check_confrict: :environment do
5
+ migrations_status =
6
+ if ActiveRecord::Base.connection.respond_to?(:migration_context)
7
+ ActiveRecord::Base.connection.migration_context.migrations_status
8
+ else
9
+ paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
10
+ ActiveRecord::Migrator.migrations_status(paths)
11
+ end
12
+
13
+ if migrations_status.map(&:third).any? { |name| name.include?('NO FILE') }
14
+ abort 'Migration conflict!'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ # class Post < ActiveRecord::Base
2
+ # belongs_to :company
3
+ # belongs_to :user
4
+ # validates :user_id, presence: true, existence: { in: -> { company.users } }
5
+ # end
6
+
7
+ module ActiveModel
8
+ module Validations
9
+ class ExistenceValidator < EachValidator
10
+ def validate_each(record, attribute, value)
11
+ unless exists?(record, value)
12
+ record.errors.add(attribute, :existence, options.except(:in).merge!(value: value))
13
+ end
14
+ end
15
+
16
+ def exists?(record, value)
17
+ unless options[:in].respond_to?(:call)
18
+ raise ArgumentError, '`in` option should be proc'
19
+ end
20
+ collection = record.instance_exec(&options[:in])
21
+ collection.exists?(value)
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Dekiru
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -12,7 +12,7 @@ describe Dekiru::Helper do
12
12
  end
13
13
  describe "#menu_link_to" do
14
14
  before do
15
- helper.stub(:current_page?).and_return(true)
15
+ allow(helper).to receive(:current_page?).and_return(true)
16
16
  end
17
17
  context "一番シンプルな呼び出し" do
18
18
  it "動くこと" do
@@ -34,7 +34,7 @@ describe Dekiru::Helper do
34
34
  end
35
35
  context "今のページじゃない" do
36
36
  before do
37
- helper.stub(:current_page?).and_return(false)
37
+ allow(helper).to receive(:current_page?).and_return(false)
38
38
  end
39
39
  it "動くこと" do
40
40
  expect(helper.menu_link_to("テキスト", "/some_path", class: "some_class")).to eq("<li class=\"\"><a class=\"some_class\" href=\"/some_path\">テキスト</a></li>")
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveModel::Validations::ExistenceValidator do
4
+ let(:user_class) do
5
+ Class.new do
6
+ def self.exists?(id)
7
+ %w[valid_id].member?(id)
8
+ end
9
+ end
10
+ end
11
+ let(:model_class) do
12
+ _options = options
13
+
14
+ Struct.new(:user_id, :users) do
15
+ include ActiveModel::Validations
16
+
17
+ def self.name
18
+ 'DummyModel'
19
+ end
20
+
21
+ validates :user_id, existence: _options
22
+ end
23
+ end
24
+
25
+ describe 'validate' do
26
+ subject(:valid?) do
27
+ model_class.new(user_id, user_class).valid?
28
+ end
29
+
30
+ context 'with exists id' do
31
+ let(:user_id) { 'valid_id' }
32
+ let(:options) { { in: -> { users } } }
33
+
34
+ it { is_expected.to eq true }
35
+ end
36
+
37
+ context 'with exists not id' do
38
+ let(:user_id) { 'invalid_id' }
39
+ let(:options) { { in: -> { users } } }
40
+
41
+ it { is_expected.to eq false }
42
+ end
43
+
44
+ context 'with invalid option' do
45
+ let(:user_id) { 'valid_id' }
46
+ let(:options) { { in: user_class } }
47
+
48
+ it { expect { valid? }.to raise_error(ArgumentError) }
49
+ end
50
+ end
51
+ 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.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Matsumura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-05 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http_accept_language
@@ -115,9 +115,13 @@ files:
115
115
  - lib/dekiru/helper.rb
116
116
  - lib/dekiru/railtie.rb
117
117
  - lib/dekiru/smtp_check_mailer.rb
118
+ - lib/dekiru/task_with_logger.rb
119
+ - lib/dekiru/tasks/db.rake
118
120
  - lib/dekiru/tasks/smtp_check.rake
121
+ - lib/dekiru/validators/existence.rb
119
122
  - lib/dekiru/version.rb
120
123
  - spec/dekiru/helper_spec.rb
124
+ - spec/dekiru/validators/existence_spec.rb
121
125
  - spec/spec_helper.rb
122
126
  homepage: ''
123
127
  licenses: []
@@ -138,10 +142,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
142
  version: '0'
139
143
  requirements: []
140
144
  rubyforge_project:
141
- rubygems_version: 2.6.12
145
+ rubygems_version: 2.7.6
142
146
  signing_key:
143
147
  specification_version: 4
144
148
  summary: Usefull helper methods for Ruby on Rails
145
149
  test_files:
146
150
  - spec/dekiru/helper_spec.rb
151
+ - spec/dekiru/validators/existence_spec.rb
147
152
  - spec/spec_helper.rb