track_changes 0.5.1 → 1.0.0.pre1
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.
- data/README.rdoc +46 -32
- data/TODO +1 -1
- data/VERSION.yml +4 -4
- data/lib/generators/track_changes/templates/initializer.rb +1 -0
- data/lib/generators/track_changes/templates/migration.rb +18 -0
- data/lib/generators/track_changes/templates/stylesheet.css +12 -0
- data/lib/generators/track_changes/track_changes_generator.rb +30 -0
- data/lib/track_changes/action_controller.rb +31 -0
- data/lib/track_changes/active_record.rb +26 -0
- data/lib/track_changes/around_save.rb +9 -0
- data/lib/track_changes/changes.rb +15 -0
- data/lib/track_changes/configuration.rb +3 -32
- data/lib/track_changes/current_user.rb +5 -0
- data/lib/track_changes/current_user_filter.rb +12 -0
- data/lib/track_changes/engine.rb +7 -0
- data/lib/track_changes.rb +11 -10
- data/test/functional/posts_controller_test.rb +39 -10
- data/test/railsapp/Gemfile +12 -0
- data/test/railsapp/Gemfile.lock +84 -0
- data/test/railsapp/Rakefile +4 -0
- data/test/{rails_root → railsapp}/app/controllers/application_controller.rb +1 -0
- data/test/railsapp/app/controllers/posts_controller.rb +40 -0
- data/test/railsapp/app/models/post.rb +3 -0
- data/test/railsapp/app/models/user.rb +3 -0
- data/test/railsapp/app/views/layouts/application.html.erb +12 -0
- data/test/railsapp/app/views/posts/_form.html.erb +13 -0
- data/test/railsapp/app/views/posts/_post.html.erb +3 -0
- data/test/railsapp/app/views/posts/edit.html.erb +5 -0
- data/test/railsapp/app/views/posts/index.html.erb +2 -0
- data/test/railsapp/config/application.rb +12 -0
- data/test/railsapp/config/boot.rb +13 -0
- data/test/railsapp/config/database.yml +5 -0
- data/test/railsapp/config/environment.rb +5 -0
- data/test/railsapp/config/environments/test.rb +10 -0
- data/test/railsapp/config/routes.rb +3 -0
- data/test/railsapp/config.ru +2 -0
- data/test/railsapp/db/test.sqlite3 +0 -0
- data/test/railsapp/log/test.log +6385 -0
- data/test/railsapp/script/rails +6 -0
- data/test/schema.rb +19 -0
- data/test/test_helper.rb +4 -26
- data/test/track_changes_test.rb +34 -0
- metadata +124 -88
- data/lib/track_changes/audit_filter.rb +0 -69
- data/lib/track_changes/base.rb +0 -9
- data/lib/track_changes/class_methods.rb +0 -74
- data/lib/track_changes/filter.rb +0 -43
- data/lib/track_changes/initializer.rb +0 -18
- data/lib/track_changes/instance_methods.rb +0 -5
- data/lib/track_changes/result.rb +0 -36
- data/test/base_test.rb +0 -20
- data/test/class_methods_test.rb +0 -29
- data/test/filter_test.rb +0 -73
- data/test/rails_root/app/controllers/posts_controller.rb +0 -36
- data/test/rails_root/app/models/audit.rb +0 -4
- data/test/rails_root/app/models/post.rb +0 -3
- data/test/rails_root/config/boot.rb +0 -110
- data/test/rails_root/config/database.yml +0 -3
- data/test/rails_root/config/environment.rb +0 -7
- data/test/rails_root/config/environments/test.rb +0 -7
- data/test/rails_root/config/initializers/new_rails_defaults.rb +0 -7
- data/test/rails_root/config/initializers/session_store.rb +0 -4
- data/test/rails_root/config/initializers/track_changes_setup.rb +0 -8
- data/test/rails_root/config/routes.rb +0 -3
- data/test/rails_root/db/migrate/20100115021125_create_audits.rb +0 -16
- data/test/rails_root/db/migrate/20100115021151_create_posts.rb +0 -15
- data/test/rails_root/log/test.log +0 -543
- data/test/rails_root/script/console +0 -3
- data/test/rails_root/script/generate +0 -3
- data/test/result_test.rb +0 -35
- data/test/track_changes/audit_filter_test.rb +0 -154
- data/test/track_changes/configuration_test.rb +0 -36
- data/test/track_changes/initializer_test.rb +0 -37
data/README.rdoc
CHANGED
@@ -1,60 +1,72 @@
|
|
1
1
|
= track_changes
|
2
2
|
|
3
|
-
TrackChanges is a Rails
|
4
|
-
|
5
|
-
Controller actions.
|
3
|
+
TrackChanges is a Rails engine to facilitate tracking changes made to your
|
4
|
+
models.
|
6
5
|
|
7
6
|
== Why?
|
8
7
|
|
9
|
-
I originally looked at the available auditing solutions
|
10
|
-
|
8
|
+
I originally looked at the available auditing solutions and it appeared that
|
9
|
+
most of them were not thread-safe.
|
10
|
+
|
11
|
+
== Requirements
|
12
|
+
|
13
|
+
* Rails 3
|
14
|
+
* A User model
|
15
|
+
|
16
|
+
=== Development Requirements
|
17
|
+
|
18
|
+
* JRuby
|
19
|
+
* Rails 3
|
11
20
|
|
12
21
|
== Installation
|
13
22
|
|
14
|
-
|
23
|
+
Add to your Gemfile:
|
24
|
+
|
25
|
+
gem 'track_changes'
|
26
|
+
|
27
|
+
Then, you can run <tt>rails generate track_changes</tt> to create the migration
|
28
|
+
file, the initializer, and copy the CSS stylesheet to your application.
|
15
29
|
|
16
30
|
== Configuration
|
17
31
|
|
18
|
-
|
19
|
-
<tt>
|
20
|
-
|
21
|
-
|
22
|
-
<tt>current_user</tt>.
|
32
|
+
Currently, the only configuration available is in the initializer
|
33
|
+
<tt>config/initializers/track_changes_configuration.rb</tt>. In this file, you
|
34
|
+
can set a constant TrackChanges::Configuration::DEFAULT_USER_FINDER to a Proc
|
35
|
+
that will return a User model when no <tt>current_user</tt> is specified.
|
23
36
|
|
24
|
-
|
37
|
+
== Model Example
|
25
38
|
|
26
|
-
|
27
|
-
|
28
|
-
serialize :change_set
|
29
|
-
end
|
39
|
+
To enable tracking for your model, add the statement <tt>track_changes</tt> in
|
40
|
+
your model definition.
|
30
41
|
|
31
|
-
Example
|
42
|
+
Example:
|
32
43
|
|
33
44
|
class Post < ActiveRecord::Base
|
34
|
-
|
45
|
+
track_changes
|
35
46
|
end
|
36
47
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
TrackChanges::Configuration object:
|
41
|
-
|
42
|
-
# These are the defaults anyways
|
43
|
-
TrackChanges::Initializer.instance do |c|
|
44
|
-
c.audit_assocation = :audits # Calls <tt>create!</tt> on this association method
|
45
|
-
c.current_user = :current_user # Controller is sent this method to obtain current user.
|
46
|
-
c.ignore_nil = true # Don't crash if a model is nil.
|
47
|
-
end
|
48
|
+
This will add a polymorphic <tt>has_many</tt> association to the Audit class. It
|
49
|
+
will also add an accessor <tt>current_user</tt> which you can set prior to
|
50
|
+
updating your model. This will be saved in the Audit entry.
|
48
51
|
|
49
52
|
== Controller Example
|
50
53
|
|
54
|
+
To enable automatic user tracking in your controllers. Add the <tt>track_changes</tt>
|
55
|
+
statement to your controller. Pass a Symbol as an argument which is the name
|
56
|
+
of the instance variable(s) (without the <tt>@</tt>). Theses instance variables
|
57
|
+
will have their <tt>current_user</tt> attribute assigned to via the controller's
|
58
|
+
<tt>current_user</tt> method.
|
59
|
+
|
60
|
+
The <tt>track_changes</tt> method in your controller will also pull in the
|
61
|
+
AuditsHelper module which provides some simple helpers.
|
62
|
+
|
63
|
+
Example:
|
64
|
+
|
51
65
|
In this example, after the `update` action is called,
|
52
66
|
the `@post` will be compared to a previous version, and
|
53
67
|
if there are any changes, an audit will be created.
|
54
68
|
|
55
69
|
class PostController < ApplicationController
|
56
|
-
include TrackChanges
|
57
|
-
|
58
70
|
before_filter :get_post, :except => [:index, :new]
|
59
71
|
|
60
72
|
# specify a single model
|
@@ -62,7 +74,7 @@ if there are any changes, an audit will be created.
|
|
62
74
|
|
63
75
|
# you can also specify multiple models
|
64
76
|
#track_changes :post1, :post2, ...
|
65
|
-
|
77
|
+
|
66
78
|
def update
|
67
79
|
if @post.update_attributes(params[:post])
|
68
80
|
flash[:notice] = "Success."
|
@@ -81,6 +93,8 @@ if there are any changes, an audit will be created.
|
|
81
93
|
end
|
82
94
|
end
|
83
95
|
|
96
|
+
Note, you must have a <tt>before_filter</tt> that assigns the model to the expected
|
97
|
+
instance variable.
|
84
98
|
|
85
99
|
== COPYRIGHT
|
86
100
|
|
data/TODO
CHANGED
data/VERSION.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
:
|
3
|
-
:
|
4
|
-
:
|
5
|
-
:
|
2
|
+
:major: 1
|
3
|
+
:minor: 0
|
4
|
+
:patch: 0
|
5
|
+
:build: pre1
|
@@ -0,0 +1 @@
|
|
1
|
+
TrackChanges::Configuration::DEFAULT_USER_FINDER = Proc.new { User.first }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateAuditsTable < ActiveRecord::Migration #:nodoc:
|
2
|
+
def self.up
|
3
|
+
create_table :audits do |t|
|
4
|
+
t.references :audited, :polymorphic => true, :null => false
|
5
|
+
t.references :user
|
6
|
+
t.text :change_set, :null => false
|
7
|
+
|
8
|
+
t.datetime :created_at, :null => false
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :audits, [:audited_id, :audited_type]
|
12
|
+
add_index :audits, [:user_id]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :audits
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class TrackChangesGenerator < Rails::Generators::Base #:nodoc:
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
source_root File.expand_path("templates", File.dirname(__FILE__))
|
8
|
+
|
9
|
+
# Implement the required interface for Rails::Generators::Migration.
|
10
|
+
# taken from http://github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb
|
11
|
+
def self.next_migration_number(dirname)
|
12
|
+
if ActiveRecord::Base.timestamped_migrations
|
13
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
14
|
+
else
|
15
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_migration_file
|
20
|
+
migration_template 'migration.rb', 'db/migrate/create_audits_table.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_layout
|
24
|
+
copy_file 'stylesheet.css', 'public/stylesheets/track_changes.css'
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_initializer_file
|
28
|
+
copy_file 'initializer.rb', 'config/initializers/track_changes_configuration.rb'
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module TrackChanges
|
2
|
+
module ActionController #:nodoc:
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
# Sets up an around filter to assign the controller's <tt>current_user</tt>
|
10
|
+
# to the given model names that are already set as instance variables in a
|
11
|
+
# prior <tt>before_filter</tt>.
|
12
|
+
#
|
13
|
+
# Example:
|
14
|
+
#
|
15
|
+
# track_changes :post
|
16
|
+
# track_changes :post, :post_attribute
|
17
|
+
#
|
18
|
+
# Currently does not work if the instance variable is anything except
|
19
|
+
# an model that has <tt>current_user</tt> accessors.
|
20
|
+
def track_changes models
|
21
|
+
models_to_track = [models].flatten
|
22
|
+
define_method(:__track_changes_to_models) { models_to_track }
|
23
|
+
|
24
|
+
self.class_eval do
|
25
|
+
helper :audits
|
26
|
+
before_filter TrackChanges::CurrentUserFilter
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module TrackChanges
|
2
|
+
module ActiveRecord #:nodoc:
|
3
|
+
def self.included(base)
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
|
9
|
+
# Enables auditing of all changes to an ActiveRecord model. Sets up an
|
10
|
+
# around filter that will create an Audit for the models <tt>changes</tt>
|
11
|
+
# attribute.
|
12
|
+
#
|
13
|
+
# In addition, this will also define a <tt>attr_accessor</tt> for <tt>current_user</tt>.
|
14
|
+
def track_changes
|
15
|
+
send :include, TrackChanges::CurrentUser
|
16
|
+
send :include, TrackChanges::Changes
|
17
|
+
|
18
|
+
self.class_eval do
|
19
|
+
has_many :audits, :as => :audited
|
20
|
+
|
21
|
+
around_save TrackChanges::AroundSave
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TrackChanges
|
2
|
+
module Changes #:nodoc:
|
3
|
+
|
4
|
+
protected
|
5
|
+
|
6
|
+
def track_changes_get_changes
|
7
|
+
@__model_changes = self.changes
|
8
|
+
end
|
9
|
+
|
10
|
+
def track_changes_save_audit
|
11
|
+
user = current_user || TrackChanges::Configuration::get_default_user
|
12
|
+
Audit.create_changes(self, @__model_changes, current_user)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,38 +1,9 @@
|
|
1
1
|
module TrackChanges
|
2
2
|
class Configuration
|
3
|
-
# The association used to create an audit. Defaults to
|
4
|
-
# <tt>:audits</tt>
|
5
|
-
#
|
6
|
-
# Example:
|
7
|
-
# :audits # => Call model.audits.create
|
8
|
-
# :changes # => Call model.changes.create
|
9
|
-
attr_accessor :audit_association
|
10
3
|
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# Ignore if the audited item is nil. Defaults to <tt>true</tt>.
|
16
|
-
attr_accessor :ignore_nil
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
self.audit_association = default_audit_association
|
20
|
-
self.current_user = default_current_user
|
21
|
-
self.ignore_nil = default_ignore_nil
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def default_audit_association
|
27
|
-
:audits
|
28
|
-
end
|
29
|
-
|
30
|
-
def default_current_user
|
31
|
-
:current_user
|
32
|
-
end
|
33
|
-
|
34
|
-
def default_ignore_nil
|
35
|
-
true
|
4
|
+
# If a constant DEFAULT_USER_FINDER is defined in this class. Call it.
|
5
|
+
def self.get_default_user
|
6
|
+
defined?(DEFAULT_USER_FINDER) && DEFAULT_USER_FINDER.call
|
36
7
|
end
|
37
8
|
end
|
38
9
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module TrackChanges
|
2
|
+
module CurrentUserFilter #:nodoc:
|
3
|
+
def self.filter(controller)
|
4
|
+
controller.send(:__track_changes_to_models).each do |model|
|
5
|
+
instance = controller.instance_variable_get("@#{model}")
|
6
|
+
return if instance.nil?
|
7
|
+
|
8
|
+
instance.current_user = controller.send(:current_user)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/track_changes.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
require 'track_changes/result'
|
2
|
-
require 'track_changes/configuration'
|
3
|
-
require 'track_changes/initializer'
|
4
|
-
require 'track_changes/audit_filter'
|
5
|
-
require 'track_changes/filter'
|
6
|
-
require 'track_changes/instance_methods'
|
7
|
-
require 'track_changes/class_methods'
|
8
|
-
require 'track_changes/base'
|
9
|
-
|
10
1
|
module TrackChanges
|
11
|
-
|
2
|
+
require 'track_changes/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
3
|
+
require 'track_changes/action_controller'
|
4
|
+
require 'track_changes/active_record'
|
5
|
+
require 'track_changes/around_save'
|
6
|
+
require 'track_changes/changes'
|
7
|
+
require 'track_changes/configuration'
|
8
|
+
require 'track_changes/current_user'
|
9
|
+
require 'track_changes/current_user_filter'
|
12
10
|
end
|
11
|
+
|
12
|
+
ActiveRecord::Base.send :include, TrackChanges::ActiveRecord
|
13
|
+
ActionController::Base.send :include, TrackChanges::ActionController
|
@@ -1,16 +1,45 @@
|
|
1
|
-
require 'test_helper'
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
2
|
|
3
3
|
class PostsControllerTest < ActionController::TestCase
|
4
|
-
|
5
|
-
post = Post.create!(:title => "Hello, World", :body => "This is a test.", :author => "Matt Haley")
|
6
|
-
assert !post.new_record?
|
4
|
+
load_schema
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def setup
|
7
|
+
@post = Post.create(:title => "Hello", :body => "Hello World")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_should_audit_changes
|
11
|
+
put :update, :id => @post.to_param, :post => { :title => "Changed" }
|
12
|
+
|
13
|
+
@post.reload
|
14
|
+
expected_change = { "title" => ["Hello", "Changed"]}
|
15
|
+
assert_equal "Changed", @post.title
|
16
|
+
assert_equal 2, @post.audits.count
|
17
|
+
assert_equal expected_change, @post.audits.desc.first.change_set
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_respect_current_user
|
21
|
+
User.delete_all
|
22
|
+
@user = User.create!(:name => "ControllerTest")
|
23
|
+
User.create!(:name => "Someone Else")
|
24
|
+
|
25
|
+
put :update, :id => @post.to_param, :post => { :title => "Changed User Test"},
|
26
|
+
:user_id => @user.id
|
27
|
+
|
28
|
+
@post.reload
|
29
|
+
audit = @post.audits.desc.first
|
30
|
+
|
31
|
+
assert_equal @user.id, audit.user_id
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_not_fail_if_current_user_nil
|
35
|
+
User.delete_all
|
36
|
+
|
37
|
+
put :update, :id => @post.to_param, :post => { :title => "Changed User Test"},
|
38
|
+
:user_id => nil
|
39
|
+
|
40
|
+
@post.reload
|
41
|
+
audit = @post.audits.desc.first
|
11
42
|
|
12
|
-
|
13
|
-
assert_equal ["Hello, World", "First post!"], audit.change_set["title"]
|
14
|
-
end
|
43
|
+
assert_equal nil, audit.user_id
|
15
44
|
end
|
16
45
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '3.0.0.rc'
|
4
|
+
|
5
|
+
if defined?(JRUBY_VERSION)
|
6
|
+
gem 'activerecord-jdbc-adapter'
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', :require => false
|
8
|
+
else
|
9
|
+
gem 'sqlite3-ruby'
|
10
|
+
end
|
11
|
+
|
12
|
+
gem 'track_changes', :path => "../.."
|
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: C:/Users/Matt/Code/track_changes
|
3
|
+
specs:
|
4
|
+
track_changes (0.5.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
abstract (1.0.0)
|
10
|
+
actionmailer (3.0.0.rc)
|
11
|
+
actionpack (= 3.0.0.rc)
|
12
|
+
mail (~> 2.2.5)
|
13
|
+
actionpack (3.0.0.rc)
|
14
|
+
activemodel (= 3.0.0.rc)
|
15
|
+
activesupport (= 3.0.0.rc)
|
16
|
+
builder (~> 2.1.2)
|
17
|
+
erubis (~> 2.6.6)
|
18
|
+
i18n (~> 0.4.1)
|
19
|
+
rack (~> 1.2.1)
|
20
|
+
rack-mount (~> 0.6.9)
|
21
|
+
rack-test (~> 0.5.4)
|
22
|
+
tzinfo (~> 0.3.22)
|
23
|
+
activemodel (3.0.0.rc)
|
24
|
+
activesupport (= 3.0.0.rc)
|
25
|
+
builder (~> 2.1.2)
|
26
|
+
i18n (~> 0.4.1)
|
27
|
+
activerecord (3.0.0.rc)
|
28
|
+
activemodel (= 3.0.0.rc)
|
29
|
+
activesupport (= 3.0.0.rc)
|
30
|
+
arel (~> 0.4.0)
|
31
|
+
tzinfo (~> 0.3.22)
|
32
|
+
activerecord-jdbc-adapter (0.9.7-java)
|
33
|
+
activerecord-jdbcsqlite3-adapter (0.9.7-java)
|
34
|
+
activerecord-jdbc-adapter (= 0.9.7)
|
35
|
+
jdbc-sqlite3 (>= 3.6.3.054)
|
36
|
+
activeresource (3.0.0.rc)
|
37
|
+
activemodel (= 3.0.0.rc)
|
38
|
+
activesupport (= 3.0.0.rc)
|
39
|
+
activesupport (3.0.0.rc)
|
40
|
+
arel (0.4.0)
|
41
|
+
activesupport (>= 3.0.0.beta)
|
42
|
+
builder (2.1.2)
|
43
|
+
erubis (2.6.6)
|
44
|
+
abstract (>= 1.0.0)
|
45
|
+
i18n (0.4.1)
|
46
|
+
jdbc-sqlite3 (3.6.3.054)
|
47
|
+
mail (2.2.5)
|
48
|
+
activesupport (>= 2.3.6)
|
49
|
+
mime-types
|
50
|
+
treetop (>= 1.4.5)
|
51
|
+
mime-types (1.16)
|
52
|
+
polyglot (0.3.1)
|
53
|
+
rack (1.2.1)
|
54
|
+
rack-mount (0.6.9)
|
55
|
+
rack (>= 1.0.0)
|
56
|
+
rack-test (0.5.4)
|
57
|
+
rack (>= 1.0)
|
58
|
+
rails (3.0.0.rc)
|
59
|
+
actionmailer (= 3.0.0.rc)
|
60
|
+
actionpack (= 3.0.0.rc)
|
61
|
+
activerecord (= 3.0.0.rc)
|
62
|
+
activeresource (= 3.0.0.rc)
|
63
|
+
activesupport (= 3.0.0.rc)
|
64
|
+
bundler (>= 1.0.0.rc.1)
|
65
|
+
railties (= 3.0.0.rc)
|
66
|
+
railties (3.0.0.rc)
|
67
|
+
actionpack (= 3.0.0.rc)
|
68
|
+
activesupport (= 3.0.0.rc)
|
69
|
+
rake (>= 0.8.3)
|
70
|
+
thor (~> 0.14.0)
|
71
|
+
rake (0.8.7)
|
72
|
+
thor (0.14.0)
|
73
|
+
treetop (1.4.8)
|
74
|
+
polyglot (>= 0.3.1)
|
75
|
+
tzinfo (0.3.22)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
java
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
activerecord-jdbc-adapter
|
82
|
+
activerecord-jdbcsqlite3-adapter
|
83
|
+
rails (= 3.0.0.rc)
|
84
|
+
track_changes!
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
before_filter :get_user
|
3
|
+
before_filter :get_post
|
4
|
+
|
5
|
+
track_changes :post
|
6
|
+
|
7
|
+
def index
|
8
|
+
@posts = Post.all
|
9
|
+
end
|
10
|
+
|
11
|
+
def edit
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def update
|
16
|
+
if @post.update_attributes(params[:post])
|
17
|
+
flash[:notice] = "Post updated"
|
18
|
+
redirect_to posts_url
|
19
|
+
else
|
20
|
+
render :action => "edit"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def get_post
|
27
|
+
Rails.logger.debug("get_post")
|
28
|
+
@post = Post.find(params[:id])
|
29
|
+
end
|
30
|
+
|
31
|
+
def get_user
|
32
|
+
Rails.logger.debug("get_user")
|
33
|
+
@user = User.find_by_id(params[:user_id])
|
34
|
+
end
|
35
|
+
|
36
|
+
def current_user
|
37
|
+
Rails.logger.debug("current_user")
|
38
|
+
@user
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
6
|
+
|
7
|
+
module Railsapp
|
8
|
+
class Application < Rails::Application
|
9
|
+
config.action_view.javascript_expansions[:defaults] = %w()
|
10
|
+
config.encoding = "utf-8"
|
11
|
+
end
|
12
|
+
end
|