event_attribute 1.0.0
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 +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +23 -0
- data/README.md +72 -0
- data/RUNNING_UNIT_TESTS +42 -0
- data/Rakefile +11 -0
- data/event_attribute.gemspec +27 -0
- data/lib/event_attribute/version.rb +3 -0
- data/lib/event_attribute.rb +96 -0
- data/test/abstract_unit.rb +11 -0
- data/test/database.yml +17 -0
- data/test/event_attribute_test.rb +146 -0
- data/test/schema.rb +7 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa4d4630a70af28e5ad77263e2eb85dceaf75371
|
4
|
+
data.tar.gz: 407b01afebb42217079da76e330cfaa12cc1eea3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30a39c9fde9a2ccb85c6aadfdad910948f2923614015e28131b804c7c90844d72c06af450ff9ebf5e41a1efd8da37f6f3c0651bd4e1dce2751817f0ec6f004bf
|
7
|
+
data.tar.gz: 0f3c5d861ed4bdcf74d2cd8667c8254b19ede23bb191848dae045a727105f9880d5ce7dda9982b0c0788f360ee41fdc18c30fc7390f636dd08b108fbef0f6f1d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
event_attribute (1.0.0)
|
5
|
+
activesupport (>= 3.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (4.0.0)
|
11
|
+
activesupport (= 4.0.0)
|
12
|
+
builder (~> 3.1.0)
|
13
|
+
activerecord (4.0.0)
|
14
|
+
activemodel (= 4.0.0)
|
15
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
16
|
+
activesupport (= 4.0.0)
|
17
|
+
arel (~> 4.0.0)
|
18
|
+
activerecord-deprecated_finders (1.0.3)
|
19
|
+
activesupport (4.0.0)
|
20
|
+
i18n (~> 0.6, >= 0.6.4)
|
21
|
+
minitest (~> 4.2)
|
22
|
+
multi_json (~> 1.3)
|
23
|
+
thread_safe (~> 0.1)
|
24
|
+
tzinfo (~> 0.3.37)
|
25
|
+
arel (4.0.0)
|
26
|
+
atomic (1.1.10)
|
27
|
+
builder (3.1.4)
|
28
|
+
i18n (0.6.4)
|
29
|
+
minitest (4.7.5)
|
30
|
+
multi_json (1.7.7)
|
31
|
+
mysql2 (0.3.11)
|
32
|
+
rake (10.1.0)
|
33
|
+
sqlite3 (1.3.7)
|
34
|
+
thread_safe (0.1.0)
|
35
|
+
atomic
|
36
|
+
tzinfo (0.3.37)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
activerecord
|
43
|
+
bundler (~> 1.3)
|
44
|
+
event_attribute!
|
45
|
+
mysql2
|
46
|
+
rake
|
47
|
+
sqlite3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2007 Jonathan Younger
|
2
|
+
Copyright (c) 2013 Andrew Kuklewicz, Chris Rhoden
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# EventAttribute
|
2
|
+
|
3
|
+
EventAttribute allows you to turn your date/datetime columns in to boolean attributes.
|
4
|
+
Idea for this was taken from http://jamis.jamisbuck.org/articles/2005/12/14/two-tips-for-working-with-databases-in-rails
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'event_attribute'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install event_attribute
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
class Referral < ActiveRecord::Base
|
24
|
+
event_attribute :applied_at, :attribute => 'pending', :nil_equals => true
|
25
|
+
event_attribute :subscribed_on
|
26
|
+
end
|
27
|
+
|
28
|
+
referral = Referral.create(:applied_at => Time.now)
|
29
|
+
referral.pending? # => false
|
30
|
+
referral.subscribed? # => false
|
31
|
+
|
32
|
+
referral.pending = true
|
33
|
+
referral.applied_at # => nil
|
34
|
+
referral.pending? # => true
|
35
|
+
|
36
|
+
referral.subscribed = true
|
37
|
+
referral.subscribed_on # => Time.now
|
38
|
+
referral.subscribed? # => true
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
48
|
+
|
49
|
+
### License
|
50
|
+
|
51
|
+
Copyright (c) 2007 Jonathan Younger, released under the MIT license
|
52
|
+
Copyright (c) 2013 Andrew Kuklewicz, Chris Rhoden
|
53
|
+
|
54
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
55
|
+
a copy of this software and associated documentation files (the
|
56
|
+
"Software"), to deal in the Software without restriction, including
|
57
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
58
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
59
|
+
permit persons to whom the Software is furnished to do so, subject to
|
60
|
+
the following conditions:
|
61
|
+
|
62
|
+
The above copyright notice and this permission notice shall be
|
63
|
+
included in all copies or substantial portions of the Software.
|
64
|
+
|
65
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
66
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
67
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
68
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
69
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
70
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
71
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
72
|
+
|
data/RUNNING_UNIT_TESTS
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
== Creating the test database
|
2
|
+
|
3
|
+
The default name for the test databases is "event_attribute_plugin_test". If you
|
4
|
+
want to use another database name then be sure to update the connection
|
5
|
+
adapter setups you want to test with in test/database.yml.
|
6
|
+
|
7
|
+
Make sure that you create database objects with the same user that you specified in
|
8
|
+
database.yml otherwise (on Postgres, at least) tests for default values will fail.
|
9
|
+
|
10
|
+
== Running with Rake
|
11
|
+
|
12
|
+
The easiest way to run the unit tests is through Rake. The default task runs
|
13
|
+
the entire test suite for the sqlite3 adapter. You can also run the suite on just
|
14
|
+
one adapter by passing the DB environment variable.
|
15
|
+
|
16
|
+
rake test DB=mysql
|
17
|
+
|
18
|
+
For more information, checkout the full array of rake tasks with "rake -T"
|
19
|
+
|
20
|
+
Rake can be found at http://rake.rubyforge.org
|
21
|
+
|
22
|
+
== Running by hand
|
23
|
+
|
24
|
+
Unit tests are located in test directory. If you only want to run a single test suite,
|
25
|
+
or don't want to bother with Rake, you can do so with something like:
|
26
|
+
|
27
|
+
cd test; DB=mysql ruby base_test.rb
|
28
|
+
|
29
|
+
That'll run the base suite using the MySQL adapter. Change the adapter
|
30
|
+
and test suite name as needed.
|
31
|
+
|
32
|
+
== Faster tests
|
33
|
+
|
34
|
+
If you are using a database that supports transactions, you can set the
|
35
|
+
"AR_TX_FIXTURES" environment variable to "yes" to use transactional fixtures.
|
36
|
+
This gives a very large speed boost. With rake:
|
37
|
+
|
38
|
+
rake AR_TX_FIXTURES=yes
|
39
|
+
|
40
|
+
Or, by hand:
|
41
|
+
|
42
|
+
AR_TX_FIXTURES=yes ruby -I connections/native_sqlite3 base_test.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'event_attribute/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "event_attribute"
|
8
|
+
spec.version = EventAttribute::VERSION
|
9
|
+
spec.authors = ["Jonathan Younger", "Andrew Kuklewicz", "chrisrhoden"]
|
10
|
+
spec.email = ["chris@prx.org"]
|
11
|
+
spec.description = %q{EventAttribute allows you to turn your date/datetime columns in to boolean attributes in ActiveRecord.}
|
12
|
+
spec.summary = %q{Idea for this was taken from http://jamis.jamisbuck.org/articles/2005/12/14/two-tips-for-working-with-databases-in-rails}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
spec.add_dependency "activesupport", ">= 3.0.0"
|
21
|
+
|
22
|
+
spec.add_development_dependency "activerecord"
|
23
|
+
spec.add_development_dependency "sqlite3"
|
24
|
+
spec.add_development_dependency "mysql2"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (c) 2007 Jonathan Younger
|
4
|
+
# Copyright (c) 2013 Andrew Kuklewicz, Chris Rhoden
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
# a copy of this software and associated documentation files (the
|
8
|
+
# "Software"), to deal in the Software without restriction, including
|
9
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
# the following conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
require 'active_record'
|
25
|
+
|
26
|
+
# EventAttribute allows you to turn your date/datetime columns in to boolean attributes.
|
27
|
+
# Idea for this was taken from http://jamis.jamisbuck.org/articles/2005/12/14/two-tips-for-working-with-databases-in-rails
|
28
|
+
#
|
29
|
+
# class Referral < ActiveRecord::Base
|
30
|
+
# event_attribute :applied_at, :attribute => 'pending', :nil_equals => true
|
31
|
+
# event_attribute :subscribed_on
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Example:
|
35
|
+
#
|
36
|
+
# referral = Referral.create(:applied_at => Time.now, :subscribed_on => nil)
|
37
|
+
# referral.pending? # => false
|
38
|
+
# referral.subscribed? # => false
|
39
|
+
#
|
40
|
+
# referral.pending = true
|
41
|
+
# referral.applied_at # => nil
|
42
|
+
# referral.pending? # => true
|
43
|
+
#
|
44
|
+
# referral.subscribed = true
|
45
|
+
# referral.subscribed_at # => Time.now
|
46
|
+
# referral.subscribed? # => true
|
47
|
+
#
|
48
|
+
# See EventAttribute::ClassMethods#event_attribute for configuration options
|
49
|
+
|
50
|
+
module EventAttribute #:nodoc:
|
51
|
+
require 'event_attribute/version'
|
52
|
+
|
53
|
+
extend ActiveSupport::Concern
|
54
|
+
|
55
|
+
module ClassMethods
|
56
|
+
# == Configuration options
|
57
|
+
#
|
58
|
+
# * <tt>attribute</tt> - name of the attribute that will be created in the model that returns true/false (default: column name minus '_at' or '_on')
|
59
|
+
# * <tt>nil_equals</tt> - whether or not the attribute should return true or false if the column is nil (default: false)
|
60
|
+
#
|
61
|
+
def event_attribute(column, options = {})
|
62
|
+
unless respond_to?(:event_attribute_attrs)
|
63
|
+
class_attribute :event_attributes
|
64
|
+
class_attribute :event_attribute_attrs
|
65
|
+
self.event_attributes, self.event_attribute_attrs = {}, {}
|
66
|
+
end
|
67
|
+
|
68
|
+
attribute = (options[:attribute] || (column.to_s =~ /_at|_on/ ? column.to_s[0...-3] : raise("Unable to create default attribute name"))).to_sym
|
69
|
+
|
70
|
+
nil_equals = options[:nil_equals] || false
|
71
|
+
|
72
|
+
self.event_attribute_attrs[attribute] = column
|
73
|
+
self.event_attributes[column] = nil_equals
|
74
|
+
|
75
|
+
create_attribute_accessors(attribute, column, nil_equals)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def create_attribute_accessors(attribute, column, nil_equals)
|
81
|
+
define_method(attribute) { (nil_equals ? self[column].nil? : !self[column].nil?) }
|
82
|
+
alias_method :"#{attribute.to_s}?", attribute
|
83
|
+
|
84
|
+
# define the method to set the field value
|
85
|
+
define_method(:"#{attribute.to_s}=") do |value|
|
86
|
+
if [true, "1", 1, "t", "true"].include? value
|
87
|
+
send("#{column}=", nil_equals ? nil : DateTime.now)
|
88
|
+
elsif [false, "0", 0, "f", "false"].include? value
|
89
|
+
send("#{column}=", nil_equals ? DateTime.now : nil)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
ActiveRecord::Base.send :include, EventAttribute
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'active_record'
|
3
|
+
require "#{File.dirname(__FILE__)}/../lib/event_attribute"
|
4
|
+
|
5
|
+
config_location = File.dirname(__FILE__) + '/database.yml'
|
6
|
+
|
7
|
+
config = YAML::load(IO.read(config_location))
|
8
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
9
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
10
|
+
|
11
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
data/test/database.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sqlite:
|
2
|
+
adapter: sqlite
|
3
|
+
database: event_attribute_plugin.sqlite.db
|
4
|
+
sqlite3:
|
5
|
+
adapter: sqlite3
|
6
|
+
database: event_attribute_plugin.sqlite3.db
|
7
|
+
postgresql:
|
8
|
+
:adapter: postgresql
|
9
|
+
:username: postgres
|
10
|
+
:password: postgres
|
11
|
+
:database: event_attribute_plugin_test
|
12
|
+
:min_messages: ERROR
|
13
|
+
mysql2:
|
14
|
+
adapter: mysql2
|
15
|
+
host: localhost
|
16
|
+
username: root
|
17
|
+
database: event_attribute_plugin_test
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/abstract_unit")
|
2
|
+
|
3
|
+
class Referral < ActiveRecord::Base
|
4
|
+
event_attribute :applied_at, :attribute => 'pending', :nil_equals => true
|
5
|
+
event_attribute :subscribed_on
|
6
|
+
end
|
7
|
+
|
8
|
+
class EventAttributeTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
Referral.delete_all
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_should_have_boolean_attribute_when_attribute_option_specified
|
14
|
+
referral = Referral.new
|
15
|
+
assert referral.respond_to?(:pending)
|
16
|
+
assert referral.respond_to?(:pending?)
|
17
|
+
assert referral.respond_to?(:pending=)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_have_default_attribute_when_attribute_option_not_specified
|
21
|
+
referral = Referral.new
|
22
|
+
assert referral.respond_to?(:subscribed)
|
23
|
+
assert referral.respond_to?(:subscribed?)
|
24
|
+
assert referral.respond_to?(:subscribed=)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_return_true_when_nil_equals_true_and_column_is_nil
|
28
|
+
referral = Referral.new(:applied_at => nil)
|
29
|
+
assert_nil referral.applied_at
|
30
|
+
assert referral.pending?
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_should_return_nil_when_nil_equals_true_and_attribute_is_true
|
34
|
+
referral = Referral.new(:pending => true)
|
35
|
+
assert referral.pending?
|
36
|
+
assert_nil referral.applied_at
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_return_nil_when_nil_equals_true_and_attribute_equals_integer_1
|
40
|
+
referral = Referral.new(:pending => 1)
|
41
|
+
assert referral.pending?
|
42
|
+
assert_nil referral.applied_at
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_should_return_nil_when_nil_equals_true_and_attribute_equals_string_1
|
46
|
+
referral = Referral.new(:pending => "1")
|
47
|
+
assert referral.pending?
|
48
|
+
assert_nil referral.applied_at
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_should_return_nil_when_nil_equals_true_and_attribute_equals_t
|
52
|
+
referral = Referral.new(:pending => "t")
|
53
|
+
assert referral.pending?
|
54
|
+
assert_nil referral.applied_at
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_should_return_false_when_nil_equals_true_and_column_is_not_nil
|
58
|
+
referral = Referral.new(:applied_at => DateTime.now)
|
59
|
+
assert_not_nil referral.applied_at
|
60
|
+
assert !referral.pending?
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_should_return_time_when_nil_equals_true_and_attribute_is_false
|
64
|
+
referral = Referral.new(:pending => false)
|
65
|
+
assert !referral.pending?
|
66
|
+
assert_kind_of DateTime, referral.applied_at
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_return_time_when_nil_equals_true_and_attribute_equals_integer_0
|
70
|
+
referral = Referral.new(:pending => 0)
|
71
|
+
assert !referral.pending?
|
72
|
+
assert_kind_of DateTime, referral.applied_at
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_should_return_time_when_nil_equals_true_and_attribute_equals_string_0
|
76
|
+
referral = Referral.new(:pending => "0")
|
77
|
+
assert !referral.pending?
|
78
|
+
assert_kind_of DateTime, referral.applied_at
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_should_return_time_when_nil_equals_true_and_attribute_equals_f
|
82
|
+
referral = Referral.new(:pending => "f")
|
83
|
+
assert !referral.pending?
|
84
|
+
assert_kind_of DateTime, referral.applied_at
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_should_return_false_when_nil_equals_false_and_column_is_nil
|
88
|
+
referral = Referral.new(:subscribed_on => nil)
|
89
|
+
assert_nil referral.subscribed_on
|
90
|
+
assert !referral.subscribed?
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_should_return_date_when_nil_equals_false_and_attribute_is_true
|
94
|
+
referral = Referral.new(:subscribed => true)
|
95
|
+
assert referral.subscribed?
|
96
|
+
assert_kind_of Date, referral.subscribed_on
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_should_return_date_when_nil_equals_false_and_attribute_equals_integer_1
|
100
|
+
referral = Referral.new(:subscribed => 1)
|
101
|
+
assert referral.subscribed?
|
102
|
+
assert_kind_of Date, referral.subscribed_on
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_should_return_date_when_nil_equals_false_and_attribute_equals_string_1
|
106
|
+
referral = Referral.new(:subscribed => "1")
|
107
|
+
assert referral.subscribed?
|
108
|
+
assert_kind_of Date, referral.subscribed_on
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_should_return_date_when_nil_equals_false_and_attribute_equals_t
|
112
|
+
referral = Referral.new(:subscribed => "t")
|
113
|
+
assert referral.subscribed?
|
114
|
+
assert_kind_of Date, referral.subscribed_on
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_should_return_true_when_nil_equals_false_and_column_is_not_nil
|
118
|
+
referral = Referral.new(:subscribed_on => DateTime.now)
|
119
|
+
assert_not_nil referral.subscribed_on
|
120
|
+
assert referral.subscribed?
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_should_return_nil_when_nil_equals_false_and_attribute_is_false
|
124
|
+
referral = Referral.new(:subscribed => false)
|
125
|
+
assert !referral.subscribed?
|
126
|
+
assert_nil referral.subscribed_on
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_should_return_nil_when_nil_equals_false_and_attribute_equals_integer_0
|
130
|
+
referral = Referral.new(:subscribed => 0)
|
131
|
+
assert !referral.subscribed?
|
132
|
+
assert_nil referral.subscribed_on
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_should_return_nil_when_nil_equals_false_and_attribute_equals_string_0
|
136
|
+
referral = Referral.new(:subscribed => "0")
|
137
|
+
assert !referral.subscribed?
|
138
|
+
assert_nil referral.subscribed_on
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_should_return_nil_when_nil_equals_false_and_attribute_equals_f
|
142
|
+
referral = Referral.new(:subscribed => "f")
|
143
|
+
assert !referral.subscribed?
|
144
|
+
assert_nil referral.subscribed_on
|
145
|
+
end
|
146
|
+
end
|
data/test/schema.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: event_attribute
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Younger
|
8
|
+
- Andrew Kuklewicz
|
9
|
+
- chrisrhoden
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 3.0.0
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: activerecord
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: sqlite3
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: mysql2
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: bundler
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.3'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '1.3'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rake
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
description: EventAttribute allows you to turn your date/datetime columns in to boolean
|
100
|
+
attributes in ActiveRecord.
|
101
|
+
email:
|
102
|
+
- chris@prx.org
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- .gitignore
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- RUNNING_UNIT_TESTS
|
113
|
+
- Rakefile
|
114
|
+
- event_attribute.gemspec
|
115
|
+
- lib/event_attribute.rb
|
116
|
+
- lib/event_attribute/version.rb
|
117
|
+
- test/abstract_unit.rb
|
118
|
+
- test/database.yml
|
119
|
+
- test/event_attribute_test.rb
|
120
|
+
- test/schema.rb
|
121
|
+
homepage: ''
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.0.3
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Idea for this was taken from http://jamis.jamisbuck.org/articles/2005/12/14/two-tips-for-working-with-databases-in-rails
|
145
|
+
test_files:
|
146
|
+
- test/abstract_unit.rb
|
147
|
+
- test/database.yml
|
148
|
+
- test/event_attribute_test.rb
|
149
|
+
- test/schema.rb
|