capybara-bootstrap-datepicker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/capybara-bootstrap-datepicker.gemspec +23 -0
- data/lib/capybara-bootstrap-datepicker.rb +64 -0
- data/lib/capybara-bootstrap-datepicker/version.rb +5 -0
- data/lib/capybara/bootstrap-datepicker.rb +1 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 181e51c051574f4ad63a68c9350bfacf64faf4fb
|
4
|
+
data.tar.gz: 0b3f95c7b05a6b56ce7ed335055ca6080d3c0fcf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 609f17fa79622d789b37a8c94ea352c7af0a43f6a179cfe0bc800b0010ab012d8a95fb29033f259f45d4c5552b86e2ea851855c6380a3b36d86e11f2d3715c8f
|
7
|
+
data.tar.gz: 03be4a2e72125a7faf4fdd7a18d8cc879f5581d1eadb7690bee5255d60acb957836c91d43674c028596e4b6f09b29f8456861935f8cfbe33b2c9c4ff6032e1f6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 François Vantomme
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Capybara::BootstrapDatepicker
|
2
|
+
|
3
|
+
Helper for triggering date input for bootstrap-datepicker javascript library
|
4
|
+
|
5
|
+
All this gem does is something very simple : allow you to trigger Bootstrap datepicker to select the date you want.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'capybara-bootstrap-datepicker', group: :test
|
12
|
+
|
13
|
+
Or, add it into your test group
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'capybara-bootstrap-datepicker'
|
17
|
+
...
|
18
|
+
end
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install capybara-bootstrap-datepicker
|
27
|
+
|
28
|
+
The gem automatically hook itself into rspec helper using Rspec.configure.
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
Just use this method inside your capybara test:
|
33
|
+
select_date(2.weeks.ago, from: "Label of the date input")
|
34
|
+
|
35
|
+
Or even:
|
36
|
+
select_date("2013-05-24", xpath: "//path_to//your_date_input", datepicker: :bootstrap)
|
37
|
+
|
38
|
+
Available options are:
|
39
|
+
from - the label of your date input
|
40
|
+
xpath - the path to your date input
|
41
|
+
datepicker - the way to fill your date input (:bootstrap = by clicking the popover using [bootstrap-datepicker](https://github.com/eternicode/bootstrap-datepicker) ; by default it just fill the input date)
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capybara-bootstrap-datepicker/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "capybara-bootstrap-datepicker"
|
8
|
+
gem.version = Capybara::BootstrapDatepicker::VERSION
|
9
|
+
gem.authors = ["François Vantomme"]
|
10
|
+
gem.email = ["akarzim@gmail.com"]
|
11
|
+
gem.description = %q{Helper for triggering date input for bootstrap-datepicker javascript library}
|
12
|
+
gem.homepage = "https://github.com/akarzim/capybara-bootstrap-datepicker"
|
13
|
+
gem.summary = gem.description
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency 'rspec'
|
22
|
+
gem.add_dependency 'capybara'
|
23
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "capybara-bootstrap-datepicker/version"
|
2
|
+
require 'rspec/core'
|
3
|
+
|
4
|
+
module Capybara
|
5
|
+
module BootstrapDatepicker
|
6
|
+
def select_date(value, options = {})
|
7
|
+
raise "Must pass a hash containing 'from' or 'xpath'" unless options.is_a?(Hash) and [:from, :xpath].any? { |k| options.has_key? k }
|
8
|
+
|
9
|
+
picker = options.delete :datepicker
|
10
|
+
format = options.delete :format
|
11
|
+
from = options.delete :from
|
12
|
+
xpath = options.delete :xpath
|
13
|
+
|
14
|
+
locator = xpath ? first(:xpath, xpath) : from
|
15
|
+
|
16
|
+
date = value.is_a?(Date) || value.is_a?(Time) ? value : Date.parse(value)
|
17
|
+
|
18
|
+
date_input = find(:fillable_field, locator, options)
|
19
|
+
|
20
|
+
case picker
|
21
|
+
when :bootstrap
|
22
|
+
date_input.click
|
23
|
+
datepicker = find(:xpath, '//body').find('.datepicker')
|
24
|
+
|
25
|
+
datepicker_years = datepicker.find('.datepicker-years', visible: false)
|
26
|
+
datepicker_months = datepicker.find('.datepicker-months', visible: false)
|
27
|
+
datepicker_days = datepicker.find('.datepicker-days', visible: false)
|
28
|
+
|
29
|
+
datepicker_current_decade = datepicker_years.find('th.datepicker-switch', visible: false)
|
30
|
+
datepicker_current_year = datepicker_months.find('th.datepicker-switch', visible: false)
|
31
|
+
datepicker_current_month = datepicker_days.find('th.datepicker-switch', visible: false)
|
32
|
+
|
33
|
+
datepicker_current_month.click if datepicker_days.visible?
|
34
|
+
datepicker_current_year.click if datepicker_months.visible?
|
35
|
+
|
36
|
+
decade_start, decade_end = datepicker_current_decade.text.split('-').map &:to_i
|
37
|
+
|
38
|
+
if date.year < decade_start.to_i
|
39
|
+
gap = decade_start/10 - date.year/10
|
40
|
+
gap.times { datepicker_years.find('th.prev').click }
|
41
|
+
elsif date.year > decade_end
|
42
|
+
gap = date.year/10 - decade_end/10
|
43
|
+
gap.times { datepicker_years.find('th.next').click }
|
44
|
+
end
|
45
|
+
|
46
|
+
datepicker_years.find('.year', text: date.year).click
|
47
|
+
datepicker_months.find('.month', text: date.strftime("%b")).click
|
48
|
+
datepicker_days.find('.day', text: date.day).click
|
49
|
+
when :jquery
|
50
|
+
raise "jQuery UI datepicker support is not implemented."
|
51
|
+
else
|
52
|
+
date = date.strftime format unless format.nil?
|
53
|
+
|
54
|
+
date_input.set "#{date}\e"
|
55
|
+
first(:xpath, '//body').click
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
RSpec.configure do |c|
|
62
|
+
c.include Capybara::BootstrapDatepicker
|
63
|
+
end
|
64
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require '../capybara-bootstrap-datepicker'
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capybara-bootstrap-datepicker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- François Vantomme
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capybara
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Helper for triggering date input for bootstrap-datepicker javascript
|
42
|
+
library
|
43
|
+
email:
|
44
|
+
- akarzim@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- capybara-bootstrap-datepicker.gemspec
|
55
|
+
- lib/capybara-bootstrap-datepicker.rb
|
56
|
+
- lib/capybara-bootstrap-datepicker/version.rb
|
57
|
+
- lib/capybara/bootstrap-datepicker.rb
|
58
|
+
homepage: https://github.com/akarzim/capybara-bootstrap-datepicker
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.0.0.rc.2
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Helper for triggering date input for bootstrap-datepicker javascript library
|
82
|
+
test_files: []
|