periodic_counter 0.1.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.
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe PeriodicCounter do
4
+
5
+ before(:all) do
6
+ $db.migrate(1)
7
+ $db.migrate(0)
8
+ $db.migrate(1)
9
+ create_counter
10
+ end
11
+
12
+ it "should not do anything but set up data" do
13
+ start
14
+ attributes = Counter.last.attributes
15
+ data = attributes.delete('counter_data')
16
+ data.delete('counter_last_day_at').to_s.should == Time.now.utc.to_s
17
+ data.delete('counter_last_2_days_at').to_s.should == Time.now.utc.to_s
18
+ data.should == {
19
+ "counter_last_day"=>1,
20
+ "counter_last_2_days"=>1
21
+ }
22
+ attributes.should == {
23
+ "id"=>1,
24
+ "counter"=>1,
25
+ "counter_last_day"=>0,
26
+ "counter_last_2_days"=>0
27
+ }
28
+ end
29
+
30
+ it "should add to counter_last_day" do
31
+ Counter.last.update_attribute :counter, 2
32
+ stub_time(Time.now + 1.day)
33
+ start
34
+ attributes = Counter.last.attributes
35
+ data = attributes.delete('counter_data')
36
+ data.delete('counter_last_day_at').to_s.should == Time.now.utc.to_s
37
+ data.delete('counter_last_2_days_at').to_s.should == (Time.now - 1.day).utc.to_s
38
+ data.should == {
39
+ "counter_last_day"=>2,
40
+ "counter_last_2_days"=>1
41
+ }
42
+ attributes.should == {
43
+ "id"=>1,
44
+ "counter"=>2,
45
+ "counter_last_day"=>1,
46
+ "counter_last_2_days"=>0
47
+ }
48
+ end
49
+
50
+ it "should add to counter_last_2_days" do
51
+ Counter.last.update_attribute :counter, 3
52
+ stub_time(Time.now + 2.days)
53
+ start
54
+ attributes = Counter.last.attributes
55
+ data = attributes.delete('counter_data')
56
+ data.delete('counter_last_day_at').to_s.should == Time.now.utc.to_s
57
+ data.delete('counter_last_2_days_at').to_s.should == Time.now.utc.to_s
58
+ data.should == {
59
+ "counter_last_day"=>3,
60
+ "counter_last_2_days"=>3
61
+ }
62
+ attributes.should == {
63
+ "id"=>1,
64
+ "counter"=>3,
65
+ "counter_last_day"=>1,
66
+ "counter_last_2_days"=>2
67
+ }
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../require")
2
+ Require.spec_helper!
3
+
4
+ Spec::Runner.configure do |config|
5
+ end
6
+
7
+ $db, $log, $mail = ActiveWrapper.setup(
8
+ :base => File.dirname(__FILE__),
9
+ :env => 'test'
10
+ )
11
+ $db.establish_connection
12
+
13
+ def create_counter
14
+ Counter.create(:counter => 1)
15
+ end
16
+
17
+ def start
18
+ PeriodicCounter.new('test', File.dirname(__FILE__))
19
+ end
20
+
21
+ def stub_time(time)
22
+ Time.stub!(:now).and_return(time)
23
+ end
24
+
25
+ class Counter < ActiveRecord::Base
26
+ serialize :counter_data
27
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: periodic_counter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Winton Welsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-06-10 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: active_wrapper
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.7
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: require
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.7
34
+ version:
35
+ description:
36
+ email: mail@wintoni.us
37
+ executables:
38
+ - periodic_counter
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.markdown
43
+ files:
44
+ - bin/periodic_counter
45
+ - lib/periodic_counter.rb
46
+ - MIT-LICENSE
47
+ - Rakefile
48
+ - README.markdown
49
+ - require.rb
50
+ - spec/config/counters.yml
51
+ - spec/config/database.yml.example
52
+ - spec/db/migrate/001_counters.rb
53
+ - spec/log/test.log
54
+ - spec/periodic_counter_spec.rb
55
+ - spec/Rakefile
56
+ - spec/spec_helper.rb
57
+ has_rdoc: true
58
+ homepage: http://github.com/winton/periodic_counter
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
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
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.3.5
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Maintains period fields on any counter column in your database
85
+ test_files: []
86
+