sbfaulkner-sequel_timestamped 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -1
- data/Rakefile +10 -2
- data/sequel_timestamped.gemspec +3 -3
- data/test/sequel_timestamped_test.rb +76 -0
- metadata +5 -4
data/README.markdown
CHANGED
@@ -25,7 +25,14 @@ Install the gem(s):
|
|
25
25
|
class Post < Sequel::Model
|
26
26
|
is :timestamped
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
|
+
## TODO
|
30
|
+
|
31
|
+
- add tests
|
32
|
+
- maybe rename sequel\_audited
|
33
|
+
- add created_by and updated_by support?
|
34
|
+
- publish in sequel www/pages/plugins
|
35
|
+
|
29
36
|
## Legal
|
30
37
|
|
31
38
|
**Author:** S. Brent Faulkner <brentf@unwwwired.net>
|
data/Rakefile
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
Gem::manage_gems
|
3
2
|
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
4
|
|
5
5
|
load File.join(File.dirname(__FILE__),'sequel_timestamped.gemspec')
|
6
6
|
|
7
7
|
Rake::GemPackageTask.new(SPEC) do |pkg|
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
# t.libs << "test"
|
12
|
+
t.pattern = 'test/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
Rake::Task[:test].comment = "Run the tests"
|
17
|
+
|
18
|
+
task :default => :test
|
data/sequel_timestamped.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
SPEC = Gem::Specification.new do |s|
|
2
2
|
# identify the gem
|
3
3
|
s.name = "sequel_timestamped"
|
4
|
-
s.version = "1.0.
|
4
|
+
s.version = "1.0.2"
|
5
5
|
s.author = "S. Brent Faulkner"
|
6
6
|
s.email = "brentf@unwwwired.net"
|
7
7
|
s.homepage = "http://github.com/sbfaulkner/sequel_timestamped"
|
@@ -9,9 +9,9 @@ SPEC = Gem::Specification.new do |s|
|
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
# description of gem
|
11
11
|
s.summary = "my take on a timestamping plugin for sequel"
|
12
|
-
s.files = %w(lib/sequel_timestamped.rb MIT-LICENSE Rakefile README.markdown sequel_timestamped.gemspec)
|
12
|
+
s.files = %w(lib/sequel_timestamped.rb MIT-LICENSE Rakefile README.markdown sequel_timestamped.gemspec test/sequel_timestamped_test.rb)
|
13
13
|
s.require_path = "lib"
|
14
|
-
|
14
|
+
s.test_file = "test/sequel_timestamped_test.rb"
|
15
15
|
s.has_rdoc = true
|
16
16
|
s.extra_rdoc_files = ["README.markdown"]
|
17
17
|
s.add_dependency "sequel"
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'sequel'
|
4
|
+
|
5
|
+
DB = Sequel.connect('sqlite:/')
|
6
|
+
# DB.execute("SET client_min_messages TO 'WARNING'")
|
7
|
+
|
8
|
+
class ItemWithoutTimestamps < Sequel::Model
|
9
|
+
set_schema do
|
10
|
+
primary_key :id
|
11
|
+
varchar :text
|
12
|
+
end
|
13
|
+
create_table!
|
14
|
+
is :timestamped
|
15
|
+
end
|
16
|
+
|
17
|
+
class ItemWithTimestamps < Sequel::Model
|
18
|
+
set_schema do
|
19
|
+
primary_key :id
|
20
|
+
varchar :text
|
21
|
+
datetime :created_at
|
22
|
+
datetime :updated_at
|
23
|
+
end
|
24
|
+
create_table!
|
25
|
+
is :timestamped
|
26
|
+
end
|
27
|
+
|
28
|
+
class Time
|
29
|
+
NOW = Time.now
|
30
|
+
|
31
|
+
def self.now
|
32
|
+
Time.at(NOW)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class SequelTimestampedTest < Test::Unit::TestCase
|
37
|
+
def test_should_create_without_timestamps
|
38
|
+
assert ItemWithoutTimestamps.create
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_update_without_timestamps
|
42
|
+
item = ItemWithoutTimestamps.create
|
43
|
+
item.update(:text => 'updated').valid?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_should_create_with_timestamps
|
47
|
+
item = ItemWithTimestamps.create
|
48
|
+
assert_equal Time::NOW.to_i, item.created_at.to_i, "expected to be now"
|
49
|
+
assert_equal Time::NOW.to_i, item.updated_at.to_i, "expected to be now"
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_create_with_specific_created_at
|
53
|
+
a_day_ago = Time.new - 24 * 60 * 60
|
54
|
+
item = ItemWithTimestamps.create(:created_at => a_day_ago)
|
55
|
+
assert_equal a_day_ago.to_i, item.created_at.to_i, "expected to be a day ago"
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_should_update_with_specific_created_at
|
59
|
+
a_day_ago = Time.new - 24 * 60 * 60
|
60
|
+
item = ItemWithTimestamps.create
|
61
|
+
item.update(:created_at => a_day_ago)
|
62
|
+
assert_equal a_day_ago.to_i, item.created_at.to_i, "expected to be a day ago"
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_should_update_with_timestamp
|
66
|
+
item = ItemWithTimestamps.create
|
67
|
+
item.update(:updated_at => nil)
|
68
|
+
assert_equal Time::NOW.to_i, item.updated_at.to_i, "expected to be now"
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_should_not_update_with_specific_timestamp
|
72
|
+
item = ItemWithTimestamps.create
|
73
|
+
item.update(:updated_at => Time.new - 24 * 60 * 60)
|
74
|
+
assert_equal Time::NOW.to_i, item.updated_at.to_i, "expected to be now"
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sbfaulkner-sequel_timestamped
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- S. Brent Faulkner
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-11 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- Rakefile
|
36
36
|
- README.markdown
|
37
37
|
- sequel_timestamped.gemspec
|
38
|
+
- test/sequel_timestamped_test.rb
|
38
39
|
has_rdoc: true
|
39
40
|
homepage: http://github.com/sbfaulkner/sequel_timestamped
|
40
41
|
post_install_message:
|
@@ -61,5 +62,5 @@ rubygems_version: 1.2.0
|
|
61
62
|
signing_key:
|
62
63
|
specification_version: 2
|
63
64
|
summary: my take on a timestamping plugin for sequel
|
64
|
-
test_files:
|
65
|
-
|
65
|
+
test_files:
|
66
|
+
- test/sequel_timestamped_test.rb
|