model_history 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6fab3fdfea879b5aaccf4d803a7549df590b7482
4
+ data.tar.gz: 3daac8c9e61e41730e928cc1fdd0547fbd2fdf38
5
+ SHA512:
6
+ metadata.gz: b50882f6352b20304c2943164282be7bb115086f0cf9b196b6582fee87f612af6eadea9521092745892fbfe6b26563d485deef12745f2ed52a9351b873683675
7
+ data.tar.gz: c5e84b352837d5cd5ec3462547446113fd06aeabd988364608077f6a2d55de58b32e0b4005ca067f7524e1b0577707db776d6709c94f5a777947a40aa8e103e1
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ - 2.0.0
5
+ - 1.9.3
6
+
7
+ before_install:
8
+ - gem update --system
9
+ - gem --version
10
+
11
+ gemfile:
12
+ - gemfiles/3.2.gemfile
13
+ - gemfiles/4.0.gemfile
14
+ - gemfiles/4.1.gemfile
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # ModelHistory
2
2
 
3
+ [![Build Status](https://travis-ci.org/patorash/model_history.png?branch=master)](https://travis-ci.org/patorash/model_history)
4
+
3
5
  Model History is a simple gem that allows you to keep track of changes to specific fields in your Rails models using the ActiveRecord::Dirty module.
4
6
 
5
7
  ## Installation
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', '3.2.19'
4
+ gem 'pg'
5
+ gem 'model_history', :path => '../'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', '~> 4.0.10'
4
+ gem 'pg'
5
+ gem 'model_history', :path => '../'
6
+
7
+ gemspec :path => '../'
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', '~> 4.1.6'
4
+ gem 'pg'
5
+ gem 'model_history', :path => '../'
6
+
7
+ gemspec :path => '../'
@@ -24,7 +24,7 @@ module ModelHistory
24
24
 
25
25
  def create_migration_file
26
26
  if self.class.orm_has_migration?
27
- migration_template 'migration.rb', 'db/migrate/create_model_history_records'
27
+ migration_template 'migration.rb', 'db/migrate/create_model_history_records.rb'
28
28
  end
29
29
  end
30
30
  end
@@ -1,7 +1,5 @@
1
1
  module ModelHistory
2
-
3
2
  module Mixin
4
-
5
3
  class CreatorProcError < StandardError ; end
6
4
 
7
5
  def self.included base
@@ -99,8 +97,8 @@ module ModelHistory
99
97
  def add_model_history_record column_name, old_value, new_value, options={}
100
98
  creator = options[:creator] || self.creator_for_model_history
101
99
 
102
- dhr_attributes = {
103
- :model => self,
100
+ mhr_attributes = {
101
+ :model => self,
104
102
  :column_name => column_name,
105
103
  :column_type => self.class.columns_hash[column_name.to_s].type,
106
104
  :old_value => old_value,
@@ -108,7 +106,7 @@ module ModelHistory
108
106
  :creator => creator
109
107
  }
110
108
 
111
- dhr = ModelHistoryRecord.new(dhr_attributes)
109
+ dhr = ModelHistoryRecord.new(mhr_attributes)
112
110
 
113
111
  # attributes for manual updates
114
112
  [:revised_created_at, :performing_manual_update].each do |attribute|
@@ -2,7 +2,7 @@ require "active_record"
2
2
 
3
3
  class ModelHistoryRecord < ActiveRecord::Base
4
4
  belongs_to :creator, :polymorphic => true
5
- belongs_to :model, :polymorphic => true
5
+ belongs_to :model, :polymorphic => true
6
6
 
7
7
  validates_presence_of :model_type, :model_id, :column_name, :column_type, :new_value
8
8
 
@@ -26,9 +26,11 @@ class ModelHistoryRecord < ActiveRecord::Base
26
26
  }
27
27
 
28
28
 
29
- attr_accessible :model, :model_id, :model_type,
30
- :column_name, :column_type, :old_value, :new_value,
31
- :creator, :creator_id, :creator_type, :revised_created_at
29
+ if ::ActiveRecord::VERSION::MAJOR < 4
30
+ attr_accessible :model, :model_id, :model_type,
31
+ :column_name, :column_type, :old_value, :new_value,
32
+ :creator, :creator_id, :creator_type, :revised_created_at
33
+ end
32
34
 
33
35
  attr_accessor :performing_manual_update
34
36
 
@@ -51,7 +53,7 @@ class ModelHistoryRecord < ActiveRecord::Base
51
53
 
52
54
  private
53
55
 
54
- def val_to_col_type attribute
56
+ def val_to_col_type(attribute)
55
57
  val_as_string = self[attribute]
56
58
  return nil if val_as_string.nil?
57
59
  case self[:column_type].to_sym
@@ -1,3 +1,3 @@
1
1
  module ModelHistory
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -6,7 +6,7 @@ require 'model_history/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'model_history'
8
8
  spec.version = ModelHistory::VERSION
9
- spec.authors = ['patorash']
9
+ spec.authors = ['Toyoaki Oko']
10
10
  spec.email = ['chariderpato@gmail.com']
11
11
  spec.description = %q{Model History is a simple gem that allows you to keep track of changes to specific fields in your Rails models using the ActiveRecord::Dirty module.}
12
12
  spec.summary = %q{Model History is a simple gem that allows you to keep track of changes to specific fields in your Rails models using the ActiveRecord::Dirty module.}
@@ -18,11 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'bundler'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'rspec'
24
- spec.add_development_dependency 'rspec-rails'
25
- spec.add_development_dependency 'activerecord'
24
+ spec.add_development_dependency 'activerecord', '>= 3.2.11'
26
25
  spec.add_development_dependency 'sqlite3'
27
- spec.add_dependency 'rails', '>= 3.2.11'
28
26
  end
data/spec/fake_app.rb CHANGED
@@ -1,24 +1,9 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'active_record'
3
- require 'action_controller/railtie'
4
- require 'action_view/helpers'
5
2
  require 'model_history'
6
3
 
7
4
  # database
8
5
  ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
9
- ActiveRecord::Base.establish_connection('test')
10
-
11
- # config
12
- app = Class.new(Rails::Application)
13
- app.config.secret_token = '3b7cd727ee24e8444053437c36cc66c4'
14
- app.config.session_store :cookie_store, :key => '_myapp_session'
15
- app.config.active_support.deprecation = :log
16
- app.initialize!
17
-
18
- # routes
19
- app.routes.draw do
20
- resources :users
21
- end
6
+ ActiveRecord::Base.establish_connection :test
22
7
 
23
8
  # models
24
9
  class User < ActiveRecord::Base
@@ -26,15 +11,13 @@ class User < ActiveRecord::Base
26
11
  validates :name, :presence => true
27
12
  end
28
13
 
29
- # controllers
30
- class ApplicationController < ActionController::Base; end
31
-
32
- # helpers
33
- Object.const_set(:ApplicationHelper, Module.new)
34
-
35
- #migrations
14
+ # migrations
36
15
  class CreateAllTables < ActiveRecord::Migration
37
16
  def self.up
38
- create_table(:users) {|t| t.string :name; t.integer :age}
17
+ create_table :users do |t|
18
+ t.string :name
19
+ t.integer :age
20
+ t.timestamps
21
+ end
39
22
  end
40
23
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  require 'spec_helper'
3
2
 
4
3
  describe User do
@@ -10,24 +9,44 @@ describe User do
10
9
  end
11
10
  it "Get user history" do
12
11
  history = @user.model_history_records.last
13
- history.model_type.should == 'User'
14
- history.column_name.should == 'name'
15
- history.column_type.should == 'string'
16
- history.old_value.should == 'Makunouchi'
17
- history.new_value.should == 'Sendo'
12
+ expect(history.model_type).to eq 'User'
13
+ expect(history.column_name).to eq 'name'
14
+ expect(history.column_type).to eq 'string'
15
+ expect(history.old_value).to eq 'Makunouchi'
16
+ expect(history.new_value).to eq 'Sendo'
18
17
  end
19
18
  it "#history_for_column" do
20
19
  histories = @user.history_for_column :name
21
- histories.should have(2).items
22
- histories.should == ['Makunouchi', 'Sendo']
20
+ expect(histories.count).to eq 2
21
+ expect(histories).to eq ['Makunouchi', 'Sendo']
22
+ end
23
+ end
24
+
25
+ context 'multi columns change' do
26
+ before do
27
+ @user = User.create!(:name => 'Makunouchi', :age => 22)
28
+ @user.update_attributes!(:name => 'Sendo', :age => 23)
29
+ end
30
+ it 'Get user histories' do
31
+ histories = ModelHistoryRecord.created_at_gte(@user.updated_at)
32
+ expect(histories.count).to eq 2
33
+ histories.each do |history|
34
+ if history.column_name == 'name'
35
+ expect(history.old_value).to eq 'Makunouchi'
36
+ expect(history.new_value).to eq 'Sendo'
37
+ elsif history.column_name == 'age'
38
+ expect(history.old_value).to eq 22
39
+ expect(history.new_value).to eq 23
40
+ end
41
+ end
23
42
  end
24
43
  end
25
44
 
26
45
  context "callback methods" do
27
46
  it "call add_model_history_record" do
28
47
  user = User.new(:name => "Makunouchi", :age => 22)
29
- user.should_receive(:set_model_history_changes)
30
- user.should_receive(:save_model_history)
48
+ expect(user).to receive(:set_model_history_changes)
49
+ expect(user).to receive(:save_model_history)
31
50
  user.save!
32
51
  end
33
52
  end
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,6 @@ require 'rspec'
7
7
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
8
  require File.join(File.dirname(__FILE__), 'fake_app')
9
9
 
10
- require 'rspec/rails'
11
10
  require 'generators/model_history/migration/templates/active_record/migration'
12
11
 
13
12
  RSpec.configure do |config|
metadata CHANGED
@@ -1,128 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
- - patorash
7
+ - Toyoaki Oko
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-17 00:00:00.000000000 Z
11
+ date: 2014-09-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '1.3'
22
- type: :development
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '1.3'
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
17
+ - - ">="
36
18
  - !ruby/object:Gem::Version
37
19
  version: '0'
38
20
  type: :development
39
21
  prerelease: false
40
22
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
23
  requirements:
43
- - - ! '>='
24
+ - - ">="
44
25
  - !ruby/object:Gem::Version
45
26
  version: '0'
46
27
  - !ruby/object:Gem::Dependency
47
- name: rspec
28
+ name: rake
48
29
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
30
  requirements:
51
- - - ! '>='
31
+ - - ">="
52
32
  - !ruby/object:Gem::Version
53
33
  version: '0'
54
34
  type: :development
55
35
  prerelease: false
56
36
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
37
  requirements:
59
- - - ! '>='
38
+ - - ">="
60
39
  - !ruby/object:Gem::Version
61
40
  version: '0'
62
41
  - !ruby/object:Gem::Dependency
63
- name: rspec-rails
42
+ name: rspec
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
44
  requirements:
67
- - - ! '>='
45
+ - - ">="
68
46
  - !ruby/object:Gem::Version
69
47
  version: '0'
70
48
  type: :development
71
49
  prerelease: false
72
50
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
51
  requirements:
75
- - - ! '>='
52
+ - - ">="
76
53
  - !ruby/object:Gem::Version
77
54
  version: '0'
78
55
  - !ruby/object:Gem::Dependency
79
56
  name: activerecord
80
57
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
58
  requirements:
83
- - - ! '>='
59
+ - - ">="
84
60
  - !ruby/object:Gem::Version
85
- version: '0'
61
+ version: 3.2.11
86
62
  type: :development
87
63
  prerelease: false
88
64
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
65
  requirements:
91
- - - ! '>='
66
+ - - ">="
92
67
  - !ruby/object:Gem::Version
93
- version: '0'
68
+ version: 3.2.11
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: sqlite3
96
71
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
72
  requirements:
99
- - - ! '>='
73
+ - - ">="
100
74
  - !ruby/object:Gem::Version
101
75
  version: '0'
102
76
  type: :development
103
77
  prerelease: false
104
78
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
79
  requirements:
107
- - - ! '>='
80
+ - - ">="
108
81
  - !ruby/object:Gem::Version
109
82
  version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: rails
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: 3.2.11
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: 3.2.11
126
83
  description: Model History is a simple gem that allows you to keep track of changes
127
84
  to specific fields in your Rails models using the ActiveRecord::Dirty module.
128
85
  email:
@@ -131,12 +88,16 @@ executables: []
131
88
  extensions: []
132
89
  extra_rdoc_files: []
133
90
  files:
134
- - .gitignore
135
- - .rspec
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
136
94
  - Gemfile
137
95
  - LICENSE.txt
138
96
  - README.md
139
97
  - Rakefile
98
+ - gemfiles/3.2.gemfile
99
+ - gemfiles/4.0.gemfile
100
+ - gemfiles/4.1.gemfile
140
101
  - lib/generators/model_history/migration/migration_generator.rb
141
102
  - lib/generators/model_history/migration/templates/active_record/migration.rb
142
103
  - lib/model_history.rb
@@ -150,33 +111,26 @@ files:
150
111
  homepage: https://github.com/patorash/model_history
151
112
  licenses:
152
113
  - MIT
114
+ metadata: {}
153
115
  post_install_message:
154
116
  rdoc_options: []
155
117
  require_paths:
156
118
  - lib
157
119
  required_ruby_version: !ruby/object:Gem::Requirement
158
- none: false
159
120
  requirements:
160
- - - ! '>='
121
+ - - ">="
161
122
  - !ruby/object:Gem::Version
162
123
  version: '0'
163
- segments:
164
- - 0
165
- hash: 1898891071957235163
166
124
  required_rubygems_version: !ruby/object:Gem::Requirement
167
- none: false
168
125
  requirements:
169
- - - ! '>='
126
+ - - ">="
170
127
  - !ruby/object:Gem::Version
171
128
  version: '0'
172
- segments:
173
- - 0
174
- hash: 1898891071957235163
175
129
  requirements: []
176
130
  rubyforge_project:
177
- rubygems_version: 1.8.25
131
+ rubygems_version: 2.2.2
178
132
  signing_key:
179
- specification_version: 3
133
+ specification_version: 4
180
134
  summary: Model History is a simple gem that allows you to keep track of changes to
181
135
  specific fields in your Rails models using the ActiveRecord::Dirty module.
182
136
  test_files: