column_timestamps 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ .ginger
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Myron Marston
1
+ Copyright (c) 2009-2010 Myron Marston
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -4,21 +4,33 @@ ActiveRecord manages your updated_at columns for you, updating the timestamp whe
4
4
  This gem provides similar, but more granular functionality: in addition to a table-wide updated_at column,
5
5
  you can have additional timestamp columns that track when specific columns change.
6
6
 
7
+ == Hompage
8
+
9
+ http://github.com/myronmarston/column_timestamps
10
+
11
+ == Installation
12
+
13
+ gem install column_timestamps
14
+
15
+ == Usage
16
+
17
+ Load the gem using Rails' 2.1+ gem support. In environment.rb:
18
+
19
+ config.gem 'column_timestamps'
20
+
7
21
  Usage is pretty simple:
8
22
  - Create a new datetime column using the naming convention <column>_updated_at.
9
23
  - Include ColumnTimestamps in your model.
10
24
 
11
25
  Example:
12
26
 
13
- # schema definition...
14
- ActiveRecord::Schema.define do
15
- create_table :users, :force => true do |t|
16
- t.string :email_address
17
- t.string :name
18
- t.string :state
19
- t.datetime :state_updated_at
20
- t.timestamps
21
- end
27
+ # in a migration...
28
+ create_table :users, :force => true do |t|
29
+ t.string :email_address
30
+ t.string :name
31
+ t.string :state
32
+ t.datetime :state_updated_at
33
+ t.timestamps
22
34
  end
23
35
 
24
36
  # Model...
@@ -28,6 +40,12 @@ Example:
28
40
 
29
41
  Anytime the state attribute of a user record is changed, the state_updated_at timestamp will be updated to reflect that.
30
42
 
43
+ == Version Compatibility
44
+
45
+ column_timestamps relies upon the dirty attributes functionality introduced to ActiveRecord in version 2.1. It works on
46
+ any version since 2.1, including 3.0.0.beta. It works on ruby {1.8.6}[[http://integrity186.heroku.com/column-timestamps]],
47
+ {1.8.7}[http://integrity187.heroku.com/column-timestamps] and {1.9.1}[http://integrity191.heroku.com/column-timestamps].
48
+
31
49
  == Note on Patches/Pull Requests
32
50
 
33
51
  * Fork the project.
@@ -40,4 +58,4 @@ Anytime the state attribute of a user record is changed, the state_updated_at ti
40
58
 
41
59
  == Copyright
42
60
 
43
- Copyright (c) 2009 Myron Marston. See LICENSE for details.
61
+ Copyright (c) 2009-2010 Myron Marston. See LICENSE for details.
data/Rakefile CHANGED
@@ -10,11 +10,11 @@ begin
10
10
  gem.email = "myron.marston@gmail.com"
11
11
  gem.homepage = "http://github.com/myronmarston/column_timestamps"
12
12
  gem.authors = ["Myron Marston"]
13
- gem.add_dependency 'activerecord'
14
- gem.add_development_dependency 'sqlite3-ruby'
13
+ gem.add_dependency 'activerecord', '>= 2.1.0'
14
+ gem.add_development_dependency 'sqlite3-ruby', '>= 1.2.5'
15
15
  gem.add_development_dependency "rspec", ">= 1.2.9"
16
- gem.add_development_dependency "rr", ">= 0.10.4"
17
16
 
17
+ gem.files.exclude 'vendor/ginger'
18
18
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
19
  end
20
20
  Jeweler::GemcutterTasks.new
@@ -61,7 +61,15 @@ rescue LoadError
61
61
  end
62
62
  end
63
63
 
64
- task :default => :spec
64
+ desc 'Run ginger tests'
65
+ task :ginger do
66
+ $LOAD_PATH << File.join(*%w[vendor ginger lib])
67
+ ARGV.clear
68
+ ARGV << 'spec'
69
+ load File.join(*%w[vendor ginger bin ginger])
70
+ end
71
+
72
+ task :default => :ginger
65
73
 
66
74
  require 'rake/rdoctask'
67
75
  Rake::RDocTask.new do |rdoc|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{column_timestamps}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Myron Marston"]
12
+ s.date = %q{2010-03-25}
13
+ s.description = %q{Works "automagically" like updated_at...just add a column named <column>_updated_at, and when your column changes, the timestamp will be updated. }
14
+ s.email = %q{myron.marston@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "column_timestamps.gemspec",
27
+ "ginger_scenarios.rb",
28
+ "lib/column_timestamps.rb",
29
+ "spec/fixtures/models.rb",
30
+ "spec/fixtures/schema.rb",
31
+ "spec/spec.opts",
32
+ "spec/spec_helper.rb",
33
+ "spec/user_spec.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/myronmarston/column_timestamps}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.6}
39
+ s.summary = %q{Keeps track of when a specific column in an ActiveRecord model changed.}
40
+ s.test_files = [
41
+ "spec/fixtures/models.rb",
42
+ "spec/fixtures/schema.rb",
43
+ "spec/spec_helper.rb",
44
+ "spec/user_spec.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.1.0"])
53
+ s.add_development_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
54
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
55
+ else
56
+ s.add_dependency(%q<activerecord>, [">= 2.1.0"])
57
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
58
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<activerecord>, [">= 2.1.0"])
62
+ s.add_dependency(%q<sqlite3-ruby>, [">= 1.2.5"])
63
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,23 @@
1
+ require 'ginger'
2
+
3
+ def create_scenario(version)
4
+ scenario = Ginger::Scenario.new("Rails #{version}")
5
+ scenario[/^active_?record$/] = version
6
+ scenario[/^active_?support$/] = version
7
+ scenario
8
+ end
9
+
10
+ Ginger.configure do |config|
11
+ config.aliases["active_record"] = "activerecord"
12
+ config.aliases["active_support"] = "activesupport"
13
+
14
+ versions = []
15
+
16
+ versions << '3.0.0.beta' unless RUBY_VERSION == '1.8.6'
17
+ versions += %w( 2.3.5 2.3.4 2.3.3 2.3.2 )
18
+ versions += %w( 2.2.3 2.2.2 2.1.2 2.1.1 2.1.0 ) if RUBY_VERSION =~ /^1\.8/
19
+
20
+ versions.each do |version|
21
+ config.scenarios << create_scenario(version)
22
+ end
23
+ end
@@ -1,4 +1,4 @@
1
- require 'activerecord'
1
+ require 'active_record'
2
2
 
3
3
  module ColumnTimestamps
4
4
  def self.included(klass)
@@ -17,7 +17,9 @@ module ColumnTimestamps
17
17
  def update_column_timestamps
18
18
  current_time = self.class.default_timezone == :utc ? Time.now.utc : Time.now
19
19
  self.class.timestamped_column_names.each do |column_name|
20
- self.send("#{column_name}_updated_at=", current_time) if self.send("#{column_name}_changed?")
20
+ if self.send(:"#{column_name}_changed?") || (!self.send(column_name).blank? && new_record?)
21
+ self.send(:"#{column_name}_updated_at=", current_time)
22
+ end
21
23
  end
22
24
  true
23
25
  end
@@ -1,10 +1,14 @@
1
- ActiveRecord::Schema.define do
2
- create_table :users, :force => true do |t|
3
- t.string :email_address
4
- t.string :name
5
- t.string :state
6
- t.datetime :name_updated_at
7
- t.datetime :state_updated_at
8
- t.timestamps
1
+ silence_stream(STDOUT) do
2
+ ActiveRecord::Schema.define do
3
+ create_table :users, :force => true do |t|
4
+ t.string :email_address
5
+ t.string :name
6
+ t.string :state
7
+ t.string :role, :default => 'user'
8
+ t.datetime :name_updated_at
9
+ t.datetime :state_updated_at
10
+ t.datetime :role_updated_at
11
+ t.timestamps
12
+ end
9
13
  end
10
- end
14
+ end
@@ -1 +1,2 @@
1
1
  --color
2
+ --format nested
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__), *%w[.. vendor ginger lib])
3
+ require 'ginger'
4
4
  require 'column_timestamps'
5
5
  require 'spec'
6
6
  require 'spec/autorun'
@@ -10,5 +10,4 @@ require 'fixtures/schema.rb'
10
10
  require 'fixtures/models.rb'
11
11
 
12
12
  Spec::Runner.configure do |config|
13
- config.mock_with :rr
14
13
  end
@@ -2,25 +2,34 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe User do
4
4
  it "should return the timestamped_column_names from #timestamped_column_names" do
5
- User.timestamped_column_names.sort.should == %w( name state )
5
+ User.timestamped_column_names.should =~ %w( name role state )
6
6
  end
7
7
 
8
8
  it "should initially have nil values for the column timestamps" do
9
9
  @user = User.new
10
10
  @user.name_updated_at.should be_nil
11
11
  @user.state_updated_at.should be_nil
12
+ @user.role_updated_at.should be_nil
12
13
  end
13
14
 
14
- it "should not set the the column timestamps when saved with name or state values" do
15
- @user = User.create!
15
+ it "should not set the the column timestamps when saved without name or state values" do
16
+ @user = User.create!; @user.reload
16
17
  @user.name_updated_at.should be_nil
17
18
  @user.state_updated_at.should be_nil
18
19
  end
19
20
 
21
+ it "should set a timestamp on creation for columns that have a default" do
22
+ @now = Time.now
23
+ Time.stub!(:now).and_return(@now)
24
+ @user = User.create!
25
+ @user.reload
26
+ @user.role_updated_at.to_s.should == @now.to_s
27
+ end
28
+
20
29
  describe "saving the record with a name value" do
21
30
  before(:each) do
22
31
  @now = @now1 = Time.now
23
- stub(Time).now { @now }
32
+ Time.stub!(:now).and_return { @now }
24
33
  @user = User.create!(:name => 'David')
25
34
  @user.reload
26
35
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: column_timestamps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Myron Marston
@@ -9,49 +14,51 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-10-19 00:00:00 -07:00
17
+ date: 2010-03-25 00:00:00 -07:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: activerecord
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
27
+ segments:
28
+ - 2
29
+ - 1
30
+ - 0
31
+ version: 2.1.0
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: sqlite3-ruby
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 5
45
+ version: 1.2.5
46
+ type: :development
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: rspec
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
40
52
  requirements:
41
53
  - - ">="
42
54
  - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 2
58
+ - 9
43
59
  version: 1.2.9
44
- version:
45
- - !ruby/object:Gem::Dependency
46
- name: rr
47
60
  type: :development
48
- version_requirement:
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: 0.10.4
54
- version:
61
+ version_requirements: *id003
55
62
  description: "Works \"automagically\" like updated_at...just add a column named <column>_updated_at, and when your column changes, the timestamp will be updated. "
56
63
  email: myron.marston@gmail.com
57
64
  executables: []
@@ -68,6 +75,8 @@ files:
68
75
  - README.rdoc
69
76
  - Rakefile
70
77
  - VERSION
78
+ - column_timestamps.gemspec
79
+ - ginger_scenarios.rb
71
80
  - lib/column_timestamps.rb
72
81
  - spec/fixtures/models.rb
73
82
  - spec/fixtures/schema.rb
@@ -87,18 +96,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
96
  requirements:
88
97
  - - ">="
89
98
  - !ruby/object:Gem::Version
99
+ segments:
100
+ - 0
90
101
  version: "0"
91
- version:
92
102
  required_rubygems_version: !ruby/object:Gem::Requirement
93
103
  requirements:
94
104
  - - ">="
95
105
  - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
96
108
  version: "0"
97
- version:
98
109
  requirements: []
99
110
 
100
111
  rubyforge_project:
101
- rubygems_version: 1.3.5
112
+ rubygems_version: 1.3.6
102
113
  signing_key:
103
114
  specification_version: 3
104
115
  summary: Keeps track of when a specific column in an ActiveRecord model changed.