boolean_datepicker 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -0
- data/db/test.sqlite3 +0 -0
- data/lib/boolean_datepicker/version.rb +1 -1
- data/lib/tasks/boolean_datepicker_tasks.rake +27 -0
- data/spec/boolean_datepicker_spec.rb +74 -0
- data/spec/reports/rspec.xml +14 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/Document.rb +3 -0
- metadata +59 -13
data/README.md
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
The gem trace the datetime of the last time a boolean field has been saved with e true value.
|
2
|
+
###Installation
|
3
|
+
gem "boolean-datepicker"
|
4
|
+
###Usage
|
5
|
+
Use the macro boolean_datepicker_on to define the boolean column you want to trace
|
6
|
+
|
7
|
+
boolean_datepicker_on :my_boolean_field
|
8
|
+
|
9
|
+
By default the datetime column required will "date_{my_field_date}". You can use a custom date column name passing a secon array elemnt like:
|
10
|
+
|
11
|
+
boolean_datepicker_on :my_boolean_field, [:another_boolean, :custom_date_field]
|
12
|
+
|
13
|
+
Anytime the boolena field is setted to true (and is modified from a precedent different value) the date column field is filled with the Time.now value.
|
14
|
+
Anyother value passed ot the boolean field rest the date filed to nil.
|
15
|
+
Gem uses the before_save callbacks
|
16
|
+
|
17
|
+
###Rspec matcher
|
18
|
+
it {should have_boolean_datepicker_on(:my_field)}
|
19
|
+
|
data/db/test.sqlite3
CHANGED
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
2
|
+
t.rspec_opts = ["-fd","--format RspecJunitFormatter", "--out spec/reports/rspec.xml"]
|
3
|
+
end
|
4
|
+
|
5
|
+
namespace :boolean_datepicker do
|
6
|
+
namespace :ci do
|
7
|
+
ENV['COVERAGE'] = 'on'
|
8
|
+
ENV['JCI'] = 'on'
|
9
|
+
ENV['RAILS_ENV'] ||= 'test'
|
10
|
+
|
11
|
+
task :migrate do
|
12
|
+
Rake::Task["db:migrate"].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
task :rspec do
|
16
|
+
rm_rf "spec/reports"
|
17
|
+
Rake::Task["spec"].invoke
|
18
|
+
end
|
19
|
+
|
20
|
+
task :cucumber do
|
21
|
+
ENV["CUCUMBER_OPTS"] = "--format junit --out features/reports --format html --out features/reports/cucumber.ht"
|
22
|
+
Rake::Task["cucumber"].invoke
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
task "boolean_datepicker:ci" => ["boolean_datepicker:ci:migrate","boolean_datepicker:ci:rspec","boolean_datepicker:ci:cucumber"]
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "boolean_datepicker" do
|
4
|
+
|
5
|
+
describe "methods generation" do
|
6
|
+
|
7
|
+
it "should have method boolean_datepicker available to ActiveRecord::Base" do
|
8
|
+
ActiveRecord::Base.singleton_methods.grep(/boolean_datepicker_on/).should_not be_nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should generate instance method boolean_datepicker_on_ok" do
|
12
|
+
Document.new.should respond_to(:boolean_datepicker_on_ok)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "when creating a new record" do
|
18
|
+
|
19
|
+
it "should set date_ok field if ok is true when model is created" do
|
20
|
+
doc = Document.create!(:ok => true)
|
21
|
+
doc.date_ok.should_not be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "before_save" do
|
27
|
+
|
28
|
+
it "should set the date_ok field to Time.now if ok is true" do
|
29
|
+
doc = Document.new(:ok => true)
|
30
|
+
doc.save!
|
31
|
+
doc.date_ok.should_not be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not change the date_ok field if ok is true but has not been changed" do
|
35
|
+
doc = Document.create!(:ok => true)
|
36
|
+
date = doc.date_ok
|
37
|
+
doc.save!
|
38
|
+
doc.date_ok.should eq date
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set the date_ok field to nil if ok value is not true" do
|
42
|
+
doc = Document.new(:ok => false)
|
43
|
+
doc.save!
|
44
|
+
doc.date_ok.should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set the date_ok field to nil if ok value was true but has been changed into not true" do
|
48
|
+
doc = Document.new(:ok => true)
|
49
|
+
doc.save!
|
50
|
+
doc.date_ok.should_not be_nil
|
51
|
+
doc.ok = false
|
52
|
+
doc.save!
|
53
|
+
doc.date_ok.should be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "custom date field name" do
|
59
|
+
|
60
|
+
it "should save the date on a custom date field" do
|
61
|
+
doc = Document.create!(:another_ok => true)
|
62
|
+
doc.save!
|
63
|
+
doc.custom_date.should_not be_nil
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "rspec matcher" do
|
69
|
+
it{Document.should have_boolean_datepicker_on(:ok)}
|
70
|
+
it{Document.should_not have_boolean_datepicker_on(:field)}
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<testsuite tests="10" failures="0" errors="0" time="0.193338" timestamp="2012-02-22T14:26:08+01:00">
|
3
|
+
<properties/>
|
4
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker methods generation should have method boolean_datepicker available to ActiveRecord::Base" time="0.039298"/>
|
5
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker methods generation should generate instance method boolean_datepicker_on_ok" time="0.011778"/>
|
6
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker when creating a new record should set date_ok field if ok is true when model is created" time="0.020582"/>
|
7
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker before_save should set the date_ok field to Time.now if ok is true" time="0.008130"/>
|
8
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker before_save should not change the date_ok field if ok is true but has not been changed" time="0.008881"/>
|
9
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker before_save should set the date_ok field to nil if ok value is not true" time="0.008456"/>
|
10
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker before_save should set the date_ok field to nil if ok value was true but has been changed into not true" time="0.013939"/>
|
11
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker custom date field name should save the date on a custom date field" time="0.010034"/>
|
12
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker rspec matcher " time="0.004141"/>
|
13
|
+
<testcase classname="/Users/andrea/dev/kemen/boolean_datepicker/spec/boolean_datepicker_spec.rb" name="boolean_datepicker rspec matcher " time="0.004011"/>
|
14
|
+
</testsuite>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'active_record'
|
4
|
+
require 'sqlite3'
|
5
|
+
|
6
|
+
require 'boolean_datepicker'
|
7
|
+
|
8
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
|
9
|
+
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "db/test.sqlite3"
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.mock_with :rspec
|
13
|
+
|
14
|
+
config.before :suite do
|
15
|
+
ActiveRecord::Base.connection.create_table(:documents,:force => true) do |t|
|
16
|
+
t.boolean :ok
|
17
|
+
t.datetime :date_ok
|
18
|
+
t.boolean :another_ok
|
19
|
+
t.datetime :custom_date
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
config.before(:each) do
|
24
|
+
Document.delete_all
|
25
|
+
end
|
26
|
+
|
27
|
+
config.after(:suite) do
|
28
|
+
ActiveRecord::Base.connection.drop_table(:documents)
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boolean_datepicker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: rspec_junit_formatter
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,31 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activerecord
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
25
46
|
- !ruby/object:Gem::Dependency
|
26
47
|
name: rspec-rails
|
27
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
28
49
|
none: false
|
29
50
|
requirements:
|
30
51
|
- - ! '>='
|
@@ -32,10 +53,15 @@ dependencies:
|
|
32
53
|
version: '0'
|
33
54
|
type: :development
|
34
55
|
prerelease: false
|
35
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
36
62
|
- !ruby/object:Gem::Dependency
|
37
63
|
name: sqlite3
|
38
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
39
65
|
none: false
|
40
66
|
requirements:
|
41
67
|
- - ! '>='
|
@@ -43,7 +69,12 @@ dependencies:
|
|
43
69
|
version: '0'
|
44
70
|
type: :development
|
45
71
|
prerelease: false
|
46
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
47
78
|
description: ''
|
48
79
|
email: acampolonghi@gmail.com
|
49
80
|
executables: []
|
@@ -55,7 +86,12 @@ files:
|
|
55
86
|
- lib/boolean_datepicker/rspec_matchers.rb
|
56
87
|
- lib/boolean_datepicker/version.rb
|
57
88
|
- lib/boolean_datepicker.rb
|
89
|
+
- lib/tasks/boolean_datepicker_tasks.rake
|
58
90
|
- README.md
|
91
|
+
- spec/boolean_datepicker_spec.rb
|
92
|
+
- spec/reports/rspec.xml
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/support/Document.rb
|
59
95
|
homepage: ''
|
60
96
|
licenses: []
|
61
97
|
post_install_message:
|
@@ -68,17 +104,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
104
|
- - ! '>='
|
69
105
|
- !ruby/object:Gem::Version
|
70
106
|
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -3618236932770814491
|
71
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
111
|
none: false
|
73
112
|
requirements:
|
74
113
|
- - ! '>='
|
75
114
|
- !ruby/object:Gem::Version
|
76
115
|
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: -3618236932770814491
|
77
119
|
requirements: []
|
78
120
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.8.
|
121
|
+
rubygems_version: 1.8.24
|
80
122
|
signing_key:
|
81
123
|
specification_version: 3
|
82
|
-
summary:
|
83
|
-
|
84
|
-
|
124
|
+
summary: Trace the datetime of the last time a boolean field has been saved with e
|
125
|
+
true value.
|
126
|
+
test_files:
|
127
|
+
- spec/boolean_datepicker_spec.rb
|
128
|
+
- spec/reports/rspec.xml
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/support/Document.rb
|