From 3ed963a0d27642bd9a4b0768937d5470f51049d1 Mon Sep 17 00:00:00 2001 From: Bryan W Clark Date: Wed, 28 Nov 2007 16:14:42 -0500 Subject: [PATCH] adding the userstamp plugin to the vendor plugins directory http://delynnberry.com/projects/userstamp --- vendor/plugins/userstamp/CHANGELOG | 3 + vendor/plugins/userstamp/README | 72 +++++ vendor/plugins/userstamp/TODO | 0 .../userstamp/doc/classes/ActiveRecord.html | 112 ++++++++ .../userstamp/doc/classes/ActiveRecord/Base.html | 165 +++++++++++ .../doc/classes/ActiveRecord/Base.src/M000015.html | 18 ++ .../doc/classes/ActiveRecord/Base.src/M000016.html | 18 ++ .../doc/classes/ActiveRecord/Userstamp.html | 204 ++++++++++++++ .../ActiveRecord/Userstamp.src/M000012.html | 26 ++ .../ActiveRecord/Userstamp.src/M000013.html | 26 ++ .../ActiveRecord/Userstamp.src/M000014.html | 22 ++ vendor/plugins/userstamp/doc/classes/Customer.html | 113 ++++++++ vendor/plugins/userstamp/doc/classes/Entry.html | 113 ++++++++ vendor/plugins/userstamp/doc/classes/Post.html | 113 ++++++++ vendor/plugins/userstamp/doc/classes/Test.html | 107 ++++++++ .../plugins/userstamp/doc/classes/Test/Unit.html | 107 ++++++++ .../userstamp/doc/classes/Test/Unit/TestCase.html | 111 ++++++++ vendor/plugins/userstamp/doc/classes/User.html | 113 ++++++++ .../userstamp/doc/classes/UserstampTest.html | 304 +++++++++++++++++++++ .../doc/classes/UserstampTest.src/M000001.html | 18 ++ .../doc/classes/UserstampTest.src/M000002.html | 19 ++ .../doc/classes/UserstampTest.src/M000003.html | 21 ++ .../doc/classes/UserstampTest.src/M000004.html | 23 ++ .../doc/classes/UserstampTest.src/M000005.html | 22 ++ .../doc/classes/UserstampTest.src/M000006.html | 23 ++ .../doc/classes/UserstampTest.src/M000007.html | 23 ++ .../doc/classes/UserstampTest.src/M000008.html | 27 ++ .../doc/classes/UserstampTest.src/M000009.html | 26 ++ .../doc/classes/UserstampTest.src/M000010.html | 26 ++ .../doc/classes/UserstampTest.src/M000011.html | 23 ++ vendor/plugins/userstamp/doc/created.rid | 1 + vendor/plugins/userstamp/doc/files/init_rb.html | 115 ++++++++ .../userstamp/doc/files/lib/userstamp_rb.html | 101 +++++++ .../userstamp/doc/files/test/abstract_unit_rb.html | 125 +++++++++ .../userstamp/doc/files/test/connection_rb.html | 108 ++++++++ .../doc/files/test/userstamp_test_rb.html | 108 ++++++++ vendor/plugins/userstamp/doc/fr_class_index.html | 37 +++ vendor/plugins/userstamp/doc/fr_file_index.html | 31 +++ vendor/plugins/userstamp/doc/fr_method_index.html | 43 +++ vendor/plugins/userstamp/doc/index.html | 24 ++ vendor/plugins/userstamp/doc/rdoc-style.css | 208 ++++++++++++++ vendor/plugins/userstamp/init.rb | 7 + vendor/plugins/userstamp/lib/userstamp.rb | 68 +++++ vendor/plugins/userstamp/test/abstract_unit.rb | 21 ++ vendor/plugins/userstamp/test/connection.rb | 15 + .../plugins/userstamp/test/fixtures/customers.yml | 3 + vendor/plugins/userstamp/test/fixtures/entries.yml | 11 + vendor/plugins/userstamp/test/fixtures/mysql.sql | 41 +++ vendor/plugins/userstamp/test/fixtures/posts.yml | 7 + vendor/plugins/userstamp/test/fixtures/users.yml | 7 + vendor/plugins/userstamp/test/userstamp_test.rb | 134 +++++++++ 51 files changed, 3213 insertions(+) create mode 100644 vendor/plugins/userstamp/CHANGELOG create mode 100644 vendor/plugins/userstamp/README create mode 100644 vendor/plugins/userstamp/TODO create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord.html create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.html create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000015.html create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000016.html create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.html create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000012.html create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000013.html create mode 100644 vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000014.html create mode 100644 vendor/plugins/userstamp/doc/classes/Customer.html create mode 100644 vendor/plugins/userstamp/doc/classes/Entry.html create mode 100644 vendor/plugins/userstamp/doc/classes/Post.html create mode 100644 vendor/plugins/userstamp/doc/classes/Test.html create mode 100644 vendor/plugins/userstamp/doc/classes/Test/Unit.html create mode 100644 vendor/plugins/userstamp/doc/classes/Test/Unit/TestCase.html create mode 100644 vendor/plugins/userstamp/doc/classes/User.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000001.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000002.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000003.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000004.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000005.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000006.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000007.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000008.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000009.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000010.html create mode 100644 vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000011.html create mode 100644 vendor/plugins/userstamp/doc/created.rid create mode 100644 vendor/plugins/userstamp/doc/files/init_rb.html create mode 100644 vendor/plugins/userstamp/doc/files/lib/userstamp_rb.html create mode 100644 vendor/plugins/userstamp/doc/files/test/abstract_unit_rb.html create mode 100644 vendor/plugins/userstamp/doc/files/test/connection_rb.html create mode 100644 vendor/plugins/userstamp/doc/files/test/userstamp_test_rb.html create mode 100644 vendor/plugins/userstamp/doc/fr_class_index.html create mode 100644 vendor/plugins/userstamp/doc/fr_file_index.html create mode 100644 vendor/plugins/userstamp/doc/fr_method_index.html create mode 100644 vendor/plugins/userstamp/doc/index.html create mode 100644 vendor/plugins/userstamp/doc/rdoc-style.css create mode 100644 vendor/plugins/userstamp/init.rb create mode 100644 vendor/plugins/userstamp/lib/userstamp.rb create mode 100644 vendor/plugins/userstamp/test/abstract_unit.rb create mode 100644 vendor/plugins/userstamp/test/connection.rb create mode 100644 vendor/plugins/userstamp/test/fixtures/customers.yml create mode 100644 vendor/plugins/userstamp/test/fixtures/entries.yml create mode 100644 vendor/plugins/userstamp/test/fixtures/mysql.sql create mode 100644 vendor/plugins/userstamp/test/fixtures/posts.yml create mode 100644 vendor/plugins/userstamp/test/fixtures/users.yml create mode 100644 vendor/plugins/userstamp/test/userstamp_test.rb diff --git a/vendor/plugins/userstamp/CHANGELOG b/vendor/plugins/userstamp/CHANGELOG new file mode 100644 index 0000000..5a33b55 --- /dev/null +++ b/vendor/plugins/userstamp/CHANGELOG @@ -0,0 +1,3 @@ + +1.0 (01-18-2006) + * Initial Release diff --git a/vendor/plugins/userstamp/README b/vendor/plugins/userstamp/README new file mode 100644 index 0000000..8851d7d --- /dev/null +++ b/vendor/plugins/userstamp/README @@ -0,0 +1,72 @@ +Userstamp Plugin (v 1.0) +======================== + +Overview +-------- +The Userstamp Plugin extends ActiveRecord::Base(http://api.rubyonrails.com/classes/ActiveRecord/Base.html) to add automatic updating of created_by and updated_by attributes of your models in much the same way that the ActiveRecord::Timestamp(http://api.rubyonrails.com/classes/ActiveRecord/Timestamp.html) module updates created_(at/on) and updated_(at/on) attributes. + +The module requires that your application's user object (User by default) contains an accessor called current_user be set with an instance of the currently logged in user (typically using a before_filter(http://api.rubyonrails.com/classes/ActionController/Filters/ClassMethods.html#M000127). This module can also be turned off on a case by case basis by setting the record_userstamps attribute of your ActiveRecord object to false. + +Installation +------------ +To install the Userstamp plugin into a current Rails application run the script/plugin script from the root of your application passing it the url of http://www.delynnberry.com/svn/code/rails/plugins/userstamp/. For example: + + script/plugin install http://www.delynnberry.com/svn/code/rails/plugins/userstamp + +Once installed you will need to restart your webserver for the plugin to be loaded into the Rails environment. + +Usage +----- +Here is a simple example for how to use the Userstamp plugin. First, create a User model object (either using the generator or manually creating the file). Adjust your model to include the current_user accessor like so: + + class User < ActiveRecord::Base + cattr_accessor :current_user + end + +Second, create another table and model that will use the Userstamp functionality (I'm using Post for this example). Be sure to add the created_by and updated_by columns to your table definition and also create a belongs_to relationship. For example: + + class Post < ActiveRecord::Base + belongs_to :created_by, :class_name => "User", :foreign_key => "created_by" + belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by" + end + +Then in your ApplicationController create a before_filter to automatically set the current_user: + + class ApplicationController < ActionController::Base + before_filter do |c| + User.current_user = User.find(c.session[:user].id) unless c.session[:user].nil? + end + end + + +Uninstall +--------- +Uninstalling is simply a matter of running script/plugin from the root of your Rails application. Except this time you pass the uninstall parameter: + + script/plugin remove userstamp + +Documentation +------------- +RDoc has been run on the plugin directory and is available in the download. + +Running Unit Tests +------------------ +There are extensive unit tests in the "test" directory of the plugin. Currently, only MySQL is supported, but +you should be able to easily fix this by looking at "connection.rb". You'll need to create a +database for the tests and put the connection information into "connection.rb" as well as import the schema file +for MySQL that can be found at "test/fixtures/mysql.sql". + +To run the test simply execute the follow from the test directory inside the Userstamp plugin directory: + + ruby userstamp_test.rb + +Bugs & Feedback +--------------- +Bug reports and feedback are always welcome. Please send them to +delynn@gmail.com with [Userstamp] in the subject line. +You can also visit (http://www.delynnberry.com/articles/category/userstamp/) and post a comment on any of the posts. + +Credits and Special Thanks +-------------------------- +The original idea for this plugin came from the Rails Wiki article entitled "Extending ActiveRecord" (http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample). +Special Thanks to Ben Reubenstein (benr75@gmail.com) for helping me stress test this plugin. \ No newline at end of file diff --git a/vendor/plugins/userstamp/TODO b/vendor/plugins/userstamp/TODO new file mode 100644 index 0000000..e69de29 diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord.html new file mode 100644 index 0000000..0c09e29 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord.html @@ -0,0 +1,112 @@ + + + + + + Module: ActiveRecord + + + + + + + + + + +
+ + + + + + + + + + +
ModuleActiveRecord
In: + + lib/userstamp.rb + +
+
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ +
+

Classes and Modules

+ + Module ActiveRecord::Userstamp
+Class ActiveRecord::Base
+ +
+ + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.html new file mode 100644 index 0000000..dd91f30 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.html @@ -0,0 +1,165 @@ + + + + + + Class: ActiveRecord::Base + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassActiveRecord::Base
In: + + lib/userstamp.rb + +
+ + test/abstract_unit.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ +
+

Methods

+ + +
+ +
+ + + +
+

Included Modules

+ + +
+ +
+ + + + + + + + + +
+

Public Class methods

+ + + +

Public Instance methods

+ +
+ + + + +
+
+
+ + +
+ + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000015.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000015.html new file mode 100644 index 0000000..8bea251 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000015.html @@ -0,0 +1,18 @@ + + + + + + relates_to_user_in (ActiveRecord::Base) + + + + +
# File lib/userstamp.rb, line 60
+    def self.relates_to_user_in(model)
+      self.user_model_name = model
+    end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000016.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000016.html new file mode 100644 index 0000000..880b2a6 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Base.src/M000016.html @@ -0,0 +1,18 @@ + + + + + + relates_to_user_in (ActiveRecord::Base) + + + + +
# File lib/userstamp.rb, line 60
+    def self.relates_to_user_in(model)
+      self.user_model_name = model
+    end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.html new file mode 100644 index 0000000..36da203 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.html @@ -0,0 +1,204 @@ + + + + + + Module: ActiveRecord::Userstamp + + + + + + + + + + +
+ + + + + + + + + + +
ModuleActiveRecord::Userstamp
In: + + lib/userstamp.rb + +
+
+
+ + +
+ + + +
+ +
+

+Active Records will automatically record the user who created and/or +updated a database objects if fields of the names created_by/created_by are +present. +

+

+This module requires that your user object (which by default is User but can be changed using the +user_model_name method) contains an accessor called +current_user and is set with the instance of the currently logged +in user (typically using a before_filter and the session. +

+

+The functionality can be turned off on a case by case basis by setting the +record_userstamps property of your ActiveRecord object to false. +

+ +
+ + +
+ +
+

Methods

+ + +
+ +
+ + + + +
+ + + + + + + + + +
+

Public Class methods

+ +
+ + + + +
+
+
+ +

Public Instance methods

+ +
+ + + + +
+

+This method is an alias for the normal create method. This is +where we set the created_by and updated_by attributes. +This only happens if the attributes exist for the model, the +record_userstamps attribute is true, and the user model has the +current_user set. +

+

+After we update those attributes we continue by running the normal +create method where the object is actually validated and saved. +

+
+
+ +
+ + + + +
+

+This method is an alias for the normal update method. This is +where we set the updated_by attribute. This only happens if the +attributes exist for the model, the record_userstamps attribute is +true, and the user model has the current_user set. +

+

+After we update those attributes we continue by running the normal +update method where the object is actually validated and saved. +

+
+
+ + +
+ + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000012.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000012.html new file mode 100644 index 0000000..31c42d8 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000012.html @@ -0,0 +1,26 @@ + + + + + + included (ActiveRecord::Userstamp) + + + + +
# File lib/userstamp.rb, line 13
+    def self.included(base)
+      super
+
+      base.class_eval do
+        alias_method :create_without_user, :create
+        alias_method :create, :create_with_user
+
+        alias_method :update_without_user, :update
+        alias_method :update, :update_with_user
+      end
+    end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000013.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000013.html new file mode 100644 index 0000000..d2b7d2e --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000013.html @@ -0,0 +1,26 @@ + + + + + + included (ActiveRecord::Userstamp) + + + + +
# File lib/userstamp.rb, line 13
+    def self.included(base)
+      super
+
+      base.class_eval do
+        alias_method :create_without_user, :create
+        alias_method :create, :create_with_user
+
+        alias_method :update_without_user, :update
+        alias_method :update, :update_with_user
+      end
+    end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000014.html b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000014.html new file mode 100644 index 0000000..f25cdcf --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/ActiveRecord/Userstamp.src/M000014.html @@ -0,0 +1,22 @@ + + + + + + create_with_user (ActiveRecord::Userstamp) + + + + +
# File lib/userstamp.rb, line 31
+    def create_with_user
+      if record_userstamps and user_model.current_user != nil
+        write_attribute(:created_by, user_model.current_user.id.to_i) if respond_to?(:created_by) and self.created_by.nil?
+        write_attribute(:updated_by, user_model.current_user.id.to_i) if respond_to?(:updated_by)
+      end
+      create_without_user
+    end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/Customer.html b/vendor/plugins/userstamp/doc/classes/Customer.html new file mode 100644 index 0000000..7eb3516 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/Customer.html @@ -0,0 +1,113 @@ + + + + + + Class: Customer + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassCustomer
In: + + test/userstamp_test.rb + +
+
Parent: + + ActiveRecord::Base + +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/Entry.html b/vendor/plugins/userstamp/doc/classes/Entry.html new file mode 100644 index 0000000..d2a78ca --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/Entry.html @@ -0,0 +1,113 @@ + + + + + + Class: Entry + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassEntry
In: + + test/userstamp_test.rb + +
+
Parent: + + ActiveRecord::Base + +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/Post.html b/vendor/plugins/userstamp/doc/classes/Post.html new file mode 100644 index 0000000..421780b --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/Post.html @@ -0,0 +1,113 @@ + + + + + + Class: Post + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassPost
In: + + test/userstamp_test.rb + +
+
Parent: + + ActiveRecord::Base + +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/Test.html b/vendor/plugins/userstamp/doc/classes/Test.html new file mode 100644 index 0000000..e8e96b8 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/Test.html @@ -0,0 +1,107 @@ + + + + + + Module: Test + + + + + + + + + + +
+ + + + + + + + + + +
ModuleTest
In: +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ +
+

Classes and Modules

+ + Module Test::Unit
+ +
+ + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/Test/Unit.html b/vendor/plugins/userstamp/doc/classes/Test/Unit.html new file mode 100644 index 0000000..60c6461 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/Test/Unit.html @@ -0,0 +1,107 @@ + + + + + + Module: Test::Unit + + + + + + + + + + +
+ + + + + + + + + + +
ModuleTest::Unit
In: +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ +
+

Classes and Modules

+ + Class Test::Unit::TestCase
+ +
+ + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/Test/Unit/TestCase.html b/vendor/plugins/userstamp/doc/classes/Test/Unit/TestCase.html new file mode 100644 index 0000000..1f8b72d --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/Test/Unit/TestCase.html @@ -0,0 +1,111 @@ + + + + + + Class: Test::Unit::TestCase + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassTest::Unit::TestCase
In: + + test/abstract_unit.rb + +
+
Parent: + Object +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/User.html b/vendor/plugins/userstamp/doc/classes/User.html new file mode 100644 index 0000000..63a2196 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/User.html @@ -0,0 +1,113 @@ + + + + + + Class: User + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassUser
In: + + test/userstamp_test.rb + +
+
Parent: + + ActiveRecord::Base + +
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.html new file mode 100644 index 0000000..1984589 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.html @@ -0,0 +1,304 @@ + + + + + + Class: UserstampTest + + + + + + + + + + +
+ + + + + + + + + + + + + + +
ClassUserstampTest
In: + + test/userstamp_test.rb + +
+
Parent: + + Test::Unit::TestCase + +
+
+ + +
+ + + +
+ + + +
+ + + +
+ + + + +
+ + + + + + + + + +
+

Public Instance methods

+ +
+ + + + +
+
+
+ +
+ + + + +
+
+
+ + + + + + + + + +
+ + + + +
+
+
+ + + +
+ + + + +
+
+
+ +
+ + + + +
+
+
+ + + +
+ + + + +
+
+
+ + +
+ + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000001.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000001.html new file mode 100644 index 0000000..a31fac6 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000001.html @@ -0,0 +1,18 @@ + + + + + + setup (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 23
+  def setup
+    User.current_user = @first_user
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000002.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000002.html new file mode 100644 index 0000000..c1d16ae --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000002.html @@ -0,0 +1,19 @@ + + + + + + teardown (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 27
+  def teardown
+    User.current_user = nil
+    Entry.user_model_name = :user
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000003.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000003.html new file mode 100644 index 0000000..d3f18a6 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000003.html @@ -0,0 +1,21 @@ + + + + + + test_ar_userstamp_loaded (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 32
+  def test_ar_userstamp_loaded
+    assert ActiveRecord::Base.include?(ActiveRecord::Userstamp)
+    assert_equal @first_user, User.current_user
+    assert_equal User, @first_entry.user_model
+    assert_equal User, @second_entry.user_model
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000004.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000004.html new file mode 100644 index 0000000..08fc13c --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000004.html @@ -0,0 +1,23 @@ + + + + + + test_column_write_method (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 39
+  def test_column_write_method
+    assert_equal @first_user, User.current_user
+    assert Entry.new.respond_to?("created_by=")
+    assert Entry.new.respond_to?("updated_by=")
+
+    assert Post.new.respond_to?("created_by=")
+    assert Post.new.respond_to?("updated_by=")
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000005.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000005.html new file mode 100644 index 0000000..b3de6a1 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000005.html @@ -0,0 +1,22 @@ + + + + + + test_column_read_method (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 48
+  def test_column_read_method
+    assert_equal @first_user, User.current_user
+    assert Entry.new.respond_to?("created_by")
+    assert Entry.new.respond_to?("updated_by")
+    assert Post.new.respond_to?("created_by")
+    assert Post.new.respond_to?("updated_by")
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000006.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000006.html new file mode 100644 index 0000000..1413906 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000006.html @@ -0,0 +1,23 @@ + + + + + + test_created_by (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 56
+  def test_created_by
+    assert_equal @first_user, User.current_user
+    assert_equal @first_user, @first_entry.created_by
+    assert_equal @second_user, @second_entry.created_by
+
+    assert_nil @first_post.created_by
+    assert_nil @second_post.created_by
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000007.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000007.html new file mode 100644 index 0000000..8bdcd76 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000007.html @@ -0,0 +1,23 @@ + + + + + + test_updated_by (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 65
+  def test_updated_by
+    assert_equal @first_user, User.current_user
+    assert_equal @first_user, @first_entry.updated_by
+    assert_equal @second_user, @second_entry.updated_by
+
+    assert_nil @first_post.updated_by
+    assert_nil @second_post.updated_by
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000008.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000008.html new file mode 100644 index 0000000..ee62f05 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000008.html @@ -0,0 +1,27 @@ + + + + + + test_create_new (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 74
+  def test_create_new
+    assert_equal @first_user, User.current_user, 
+    third_user = User.create("name" => "Tester Three")
+    User.current_user = third_user
+    assert_equal third_user, User.current_user
+
+    third_entry = Entry.create("name" => "Third Entry")
+
+    assert_equal User, third_entry.user_model
+    assert_equal third_user, third_entry.created_by
+    assert_equal third_user, third_entry.updated_by
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000009.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000009.html new file mode 100644 index 0000000..9c20758 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000009.html @@ -0,0 +1,26 @@ + + + + + + test_update_entry (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 87
+  def test_update_entry
+    assert_equal @first_user, User.current_user
+    @second_entry.update_attribute("name", "Updated by First User")
+
+    User.current_user = @second_user
+    assert_equal @second_user, User.current_user
+    @first_entry.update_attribute("name", "Updated by Second User")
+
+    assert_equal @first_user, @second_entry.updated_by
+    assert_equal @second_user, @first_entry.updated_by
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000010.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000010.html new file mode 100644 index 0000000..0cbb164 --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000010.html @@ -0,0 +1,26 @@ + + + + + + test_create_and_update_entry (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 99
+  def test_create_and_update_entry
+    assert_equal @first_user, User.current_user
+
+    third_entry = Entry.create("name" => "Third Entry")
+    User.current_user = @second_user
+    assert_equal @second_user, User.current_user
+    
+    third_entry.update_attribute("name", "Updated by Second User")
+    assert_equal @first_user, third_entry.created_by
+    assert_equal @second_user, third_entry.updated_by
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000011.html b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000011.html new file mode 100644 index 0000000..6269e9b --- /dev/null +++ b/vendor/plugins/userstamp/doc/classes/UserstampTest.src/M000011.html @@ -0,0 +1,23 @@ + + + + + + test_update_with_nil_current_user (UserstampTest) + + + + +
# File test/userstamp_test.rb, line 111
+  def test_update_with_nil_current_user
+    assert_equal @first_user, User.current_user
+
+    @first_entry.update_attribute("name", "Updated by Nil")
+
+    assert_equal @first_user, @first_entry.created_by
+    assert_equal @first_user, @first_entry.updated_by
+  end
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/created.rid b/vendor/plugins/userstamp/doc/created.rid new file mode 100644 index 0000000..8a96b7b --- /dev/null +++ b/vendor/plugins/userstamp/doc/created.rid @@ -0,0 +1 @@ +Sat Jan 21 17:08:50 MST 2006 diff --git a/vendor/plugins/userstamp/doc/files/init_rb.html b/vendor/plugins/userstamp/doc/files/init_rb.html new file mode 100644 index 0000000..4f823c7 --- /dev/null +++ b/vendor/plugins/userstamp/doc/files/init_rb.html @@ -0,0 +1,115 @@ + + + + + + File: init.rb + + + + + + + + + + +
+

init.rb

+ + + + + + + + + +
Path:init.rb +
Last Update:Sat Jan 21 17:08:40 MST 2006
+
+ + +
+ + + +
+ +
+

+plugin init file for rails this file will be picked up by rails +automatically and add the userstamp extensions to rails +

+ +
+ +
+

Required files

+ +
+ userstamp   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/files/lib/userstamp_rb.html b/vendor/plugins/userstamp/doc/files/lib/userstamp_rb.html new file mode 100644 index 0000000..3035a57 --- /dev/null +++ b/vendor/plugins/userstamp/doc/files/lib/userstamp_rb.html @@ -0,0 +1,101 @@ + + + + + + File: userstamp.rb + + + + + + + + + + +
+

userstamp.rb

+ + + + + + + + + +
Path:lib/userstamp.rb +
Last Update:Sat Jan 21 17:08:18 MST 2006
+
+ + +
+ + + +
+ + + +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/files/test/abstract_unit_rb.html b/vendor/plugins/userstamp/doc/files/test/abstract_unit_rb.html new file mode 100644 index 0000000..74c5d55 --- /dev/null +++ b/vendor/plugins/userstamp/doc/files/test/abstract_unit_rb.html @@ -0,0 +1,125 @@ + + + + + + File: abstract_unit.rb + + + + + + + + + + +
+

abstract_unit.rb

+ + + + + + + + + +
Path:test/abstract_unit.rb +
Last Update:Sat Jan 21 17:08:17 MST 2006
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ test/unit   + rubygems   + connection   + active_record/fixtures   + userstamp.rb   +
+
+ +
+ + +
+ + + + +
+ + +
+

Constants

+ +
+ + + + + + +
RAILS_ROOT=File.dirname(__FILE__)
+
+
+ + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/files/test/connection_rb.html b/vendor/plugins/userstamp/doc/files/test/connection_rb.html new file mode 100644 index 0000000..c979b81 --- /dev/null +++ b/vendor/plugins/userstamp/doc/files/test/connection_rb.html @@ -0,0 +1,108 @@ + + + + + + File: connection.rb + + + + + + + + + + +
+

connection.rb

+ + + + + + + + + +
Path:test/connection.rb +
Last Update:Sat Jan 21 17:08:17 MST 2006
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ logger   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/files/test/userstamp_test_rb.html b/vendor/plugins/userstamp/doc/files/test/userstamp_test_rb.html new file mode 100644 index 0000000..7fe9fac --- /dev/null +++ b/vendor/plugins/userstamp/doc/files/test/userstamp_test_rb.html @@ -0,0 +1,108 @@ + + + + + + File: userstamp_test.rb + + + + + + + + + + +
+

userstamp_test.rb

+ + + + + + + + + +
Path:test/userstamp_test.rb +
Last Update:Sat Jan 21 17:08:17 MST 2006
+
+ + +
+ + + +
+ + +
+

Required files

+ +
+ abstract_unit   +
+
+ +
+ + +
+ + + + +
+ + + + + + + + + + + +
+ + +
+

[Validate]

+
+ + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/fr_class_index.html b/vendor/plugins/userstamp/doc/fr_class_index.html new file mode 100644 index 0000000..f9188fe --- /dev/null +++ b/vendor/plugins/userstamp/doc/fr_class_index.html @@ -0,0 +1,37 @@ + + + + + + + + Classes + + + + + +
+

Classes

+ +
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/fr_file_index.html b/vendor/plugins/userstamp/doc/fr_file_index.html new file mode 100644 index 0000000..fcf1f62 --- /dev/null +++ b/vendor/plugins/userstamp/doc/fr_file_index.html @@ -0,0 +1,31 @@ + + + + + + + + Files + + + + + +
+

Files

+ +
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/fr_method_index.html b/vendor/plugins/userstamp/doc/fr_method_index.html new file mode 100644 index 0000000..2d42900 --- /dev/null +++ b/vendor/plugins/userstamp/doc/fr_method_index.html @@ -0,0 +1,43 @@ + + + + + + + + Methods + + + + + +
+

Methods

+ +
+ + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/index.html b/vendor/plugins/userstamp/doc/index.html new file mode 100644 index 0000000..e144b5b --- /dev/null +++ b/vendor/plugins/userstamp/doc/index.html @@ -0,0 +1,24 @@ + + + + + + + RDoc Documentation + + + + + + + + + + + \ No newline at end of file diff --git a/vendor/plugins/userstamp/doc/rdoc-style.css b/vendor/plugins/userstamp/doc/rdoc-style.css new file mode 100644 index 0000000..44c7b3d --- /dev/null +++ b/vendor/plugins/userstamp/doc/rdoc-style.css @@ -0,0 +1,208 @@ + +body { + font-family: Verdana,Arial,Helvetica,sans-serif; + font-size: 90%; + margin: 0; + margin-left: 40px; + padding: 0; + background: white; +} + +h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; } +h1 { font-size: 150%; } +h2,h3,h4 { margin-top: 1em; } + +a { background: #eef; color: #039; text-decoration: none; } +a:hover { background: #039; color: #eef; } + +/* Override the base stylesheet's Anchor inside a table cell */ +td > a { + background: transparent; + color: #039; + text-decoration: none; +} + +/* and inside a section title */ +.section-title > a { + background: transparent; + color: #eee; + text-decoration: none; +} + +/* === Structural elements =================================== */ + +div#index { + margin: 0; + margin-left: -40px; + padding: 0; + font-size: 90%; +} + + +div#index a { + margin-left: 0.7em; +} + +div#index .section-bar { + margin-left: 0px; + padding-left: 0.7em; + background: #ccc; + font-size: small; +} + + +div#classHeader, div#fileHeader { + width: auto; + color: white; + padding: 0.5em 1.5em 0.5em 1.5em; + margin: 0; + margin-left: -40px; + border-bottom: 3px solid #006; +} + +div#classHeader a, div#fileHeader a { + background: inherit; + color: white; +} + +div#classHeader td, div#fileHeader td { + background: inherit; + color: white; +} + + +div#fileHeader { + background: #057; +} + +div#classHeader { + background: #048; +} + + +.class-name-in-header { + font-size: 180%; + font-weight: bold; +} + + +div#bodyContent { + padding: 0 1.5em 0 1.5em; +} + +div#description { + padding: 0.5em 1.5em; + background: #efefef; + border: 1px dotted #999; +} + +div#description h1,h2,h3,h4,h5,h6 { + color: #125;; + background: transparent; +} + +div#validator-badges { + text-align: center; +} +div#validator-badges img { border: 0; } + +div#copyright { + color: #333; + background: #efefef; + font: 0.75em sans-serif; + margin-top: 5em; + margin-bottom: 0; + padding: 0.5em 2em; +} + + +/* === Classes =================================== */ + +table.header-table { + color: white; + font-size: small; +} + +.type-note { + font-size: small; + color: #DEDEDE; +} + +.xxsection-bar { + background: #eee; + color: #333; + padding: 3px; +} + +.section-bar { + color: #333; + border-bottom: 1px solid #999; + margin-left: -20px; +} + + +.section-title { + background: #79a; + color: #eee; + padding: 3px; + margin-top: 2em; + margin-left: -30px; + border: 1px solid #999; +} + +.top-aligned-row { vertical-align: top } +.bottom-aligned-row { vertical-align: bottom } + +/* --- Context section classes ----------------------- */ + +.context-row { } +.context-item-name { font-family: monospace; font-weight: bold; color: black; } +.context-item-value { font-size: small; color: #448; } +.context-item-desc { color: #333; padding-left: 2em; } + +/* --- Method classes -------------------------- */ +.method-detail { + background: #efefef; + padding: 0; + margin-top: 0.5em; + margin-bottom: 1em; + border: 1px dotted #ccc; +} +.method-heading { + color: black; + background: #ccc; + border-bottom: 1px solid #666; + padding: 0.2em 0.5em 0 0.5em; +} +.method-signature { color: black; background: inherit; } +.method-name { font-weight: bold; } +.method-args { font-style: italic; } +.method-description { padding: 0 0.5em 0 0.5em; } + +/* --- Source code sections -------------------- */ + +a.source-toggle { font-size: 90%; } +div.method-source-code { + background: #262626; + color: #ffdead; + margin: 1em; + padding: 0.5em; + border: 1px dashed #999; + overflow: hidden; +} + +div.method-source-code pre { color: #ffdead; overflow: hidden; } + +/* --- Ruby keyword styles --------------------- */ + +.standalone-code { background: #221111; color: #ffdead; overflow: hidden; } + +.ruby-constant { color: #7fffd4; background: transparent; } +.ruby-keyword { color: #00ffff; background: transparent; } +.ruby-ivar { color: #eedd82; background: transparent; } +.ruby-operator { color: #00ffee; background: transparent; } +.ruby-identifier { color: #ffdead; background: transparent; } +.ruby-node { color: #ffa07a; background: transparent; } +.ruby-comment { color: #b22222; font-weight: bold; background: transparent; } +.ruby-regexp { color: #ffa07a; background: transparent; } +.ruby-value { color: #7fffd4; background: transparent; } \ No newline at end of file diff --git a/vendor/plugins/userstamp/init.rb b/vendor/plugins/userstamp/init.rb new file mode 100644 index 0000000..2a42f58 --- /dev/null +++ b/vendor/plugins/userstamp/init.rb @@ -0,0 +1,7 @@ +# plugin init file for rails +# this file will be picked up by rails automatically and +# add the userstamp extensions to rails + +require 'userstamp' + +ActiveRecord::Base.send(:include, ActiveRecord::Userstamp) \ No newline at end of file diff --git a/vendor/plugins/userstamp/lib/userstamp.rb b/vendor/plugins/userstamp/lib/userstamp.rb new file mode 100644 index 0000000..eb43004 --- /dev/null +++ b/vendor/plugins/userstamp/lib/userstamp.rb @@ -0,0 +1,68 @@ +module ActiveRecord + # Active Records will automatically record the user who created and/or updated a database objects + # if fields of the names created_by/created_by are present. + # + # This module requires that your user object (which by default is User but can be changed + # using the user_model_name method) contains an accessor called current_user and + # is set with the instance of the currently logged in user (typically using a before_filter and the + # session. + # + # The functionality can be turned off on a case by case basis by setting the record_userstamps + # property of your ActiveRecord object to false. + module Userstamp + def self.included(base) + super + + base.class_eval do + alias_method :create_without_user, :create + alias_method :create, :create_with_user + + alias_method :update_without_user, :update + alias_method :update, :update_with_user + end + end + + # This method is an alias for the normal create method. This is where we set the created_by + # and updated_by attributes. This only happens if the attributes exist for the model, the + # record_userstamps attribute is true, and the user model has the current_user set. + # + # After we update those attributes we continue by running the normal create method where the object + # is actually validated and saved. + def create_with_user + if record_userstamps and user_model.current_user != nil + write_attribute(:created_by, user_model.current_user.id.to_i) if respond_to?(:created_by) and self.created_by.nil? + write_attribute(:updated_by, user_model.current_user.id.to_i) if respond_to?(:updated_by) + end + create_without_user + end + + # This method is an alias for the normal update method. This is where we set the updated_by + # attribute. This only happens if the attributes exist for the model, the record_userstamps + # attribute is true, and the user model has the current_user set. + # + # After we update those attributes we continue by running the normal update method where the object + # is actually validated and saved. + def update_with_user + if record_userstamps and user_model.current_user != nil + write_attribute(:updated_by, user_model.current_user.id.to_i) if respond_to?(:updated_by) + end + update_without_user + end + end + + class Base + @@user_model_name = :users + cattr_accessor :user_model_name + + @@record_userstamps = true + cattr_accessor :record_userstamps + + def self.relates_to_user_in(model) + self.user_model_name = model + end + + def user_model + Object.const_get(self.user_model_name.to_s.singularize.humanize) + end + end +end diff --git a/vendor/plugins/userstamp/test/abstract_unit.rb b/vendor/plugins/userstamp/test/abstract_unit.rb new file mode 100644 index 0000000..5059588 --- /dev/null +++ b/vendor/plugins/userstamp/test/abstract_unit.rb @@ -0,0 +1,21 @@ +require 'test/unit' +require 'rubygems' +require_gem 'activesupport' +require_gem 'activerecord' +require 'connection' +require 'active_record/fixtures' + +RAILS_ROOT = File.dirname(__FILE__) + +$: << "../lib" + +require 'userstamp.rb' + +class ActiveRecord::Base + include ActiveRecord::Userstamp +end + + +class Test::Unit::TestCase + self.fixture_path = File.dirname(__FILE__) + "/fixtures/" +end \ No newline at end of file diff --git a/vendor/plugins/userstamp/test/connection.rb b/vendor/plugins/userstamp/test/connection.rb new file mode 100644 index 0000000..f4d136f --- /dev/null +++ b/vendor/plugins/userstamp/test/connection.rb @@ -0,0 +1,15 @@ +print "Using native MySQL\n" +require 'logger' + +ActiveRecord::Base.logger = Logger.new("debug.log") + +db = 'userstamp_test' + +ActiveRecord::Base.establish_connection( + :adapter => "mysql", + :host => "localhost", + :username => "root", + :password => "", + :database => db, + :socket => "/var/run/mysqld/mysqld.sock" +) diff --git a/vendor/plugins/userstamp/test/fixtures/customers.yml b/vendor/plugins/userstamp/test/fixtures/customers.yml new file mode 100644 index 0000000..cafc69f --- /dev/null +++ b/vendor/plugins/userstamp/test/fixtures/customers.yml @@ -0,0 +1,3 @@ +first_customer: + id: 1 + name: Customer One \ No newline at end of file diff --git a/vendor/plugins/userstamp/test/fixtures/entries.yml b/vendor/plugins/userstamp/test/fixtures/entries.yml new file mode 100644 index 0000000..d4d942e --- /dev/null +++ b/vendor/plugins/userstamp/test/fixtures/entries.yml @@ -0,0 +1,11 @@ +first_entry: + id: 1 + name: Entry One + created_by: 1 + updated_by: 1 + +second_entry: + id: 2 + name: Entry Two + created_by: 2 + updated_by: 2 \ No newline at end of file diff --git a/vendor/plugins/userstamp/test/fixtures/mysql.sql b/vendor/plugins/userstamp/test/fixtures/mysql.sql new file mode 100644 index 0000000..f736ef8 --- /dev/null +++ b/vendor/plugins/userstamp/test/fixtures/mysql.sql @@ -0,0 +1,41 @@ +-- MySQL dump 9.11 +-- +-- Host: localhost Database: userstamp_test +-- ------------------------------------------------------ +-- Server version 4.0.24 + +-- +-- Table structure for table `entries` +-- + +DROP TABLE IF EXISTS users; +CREATE TABLE users ( + id int(11) NOT NULL auto_increment, + name varchar(255), + PRIMARY KEY (id) +) TYPE=MyISAM; + +DROP TABLE IF EXISTS customers; +CREATE TABLE customers ( + id int(11) NOT NULL auto_increment, + name varchar(255), + PRIMARY KEY (id) +) TYPE=MyISAM; + +DROP TABLE IF EXISTS entries; +CREATE TABLE entries ( + id int(11) NOT NULL auto_increment, + name varchar(255), + created_by int(11) default 0, + updated_by int(11) default 0, + PRIMARY KEY (id) +) TYPE=MyISAM; + +DROP TABLE IF EXISTS posts; +CREATE TABLE posts ( + id int(11) NOT NULL auto_increment, + name varchar(255), + created_by int(11) default 0, + updated_by int(11) default 0, + PRIMARY KEY (id) +) TYPE=MyISAM; diff --git a/vendor/plugins/userstamp/test/fixtures/posts.yml b/vendor/plugins/userstamp/test/fixtures/posts.yml new file mode 100644 index 0000000..e3031e3 --- /dev/null +++ b/vendor/plugins/userstamp/test/fixtures/posts.yml @@ -0,0 +1,7 @@ +first_post: + id: 1 + name: Post One + +second_post: + id: 2 + name: Post Two \ No newline at end of file diff --git a/vendor/plugins/userstamp/test/fixtures/users.yml b/vendor/plugins/userstamp/test/fixtures/users.yml new file mode 100644 index 0000000..95e36c7 --- /dev/null +++ b/vendor/plugins/userstamp/test/fixtures/users.yml @@ -0,0 +1,7 @@ +first_user: + id: 1 + name: Tester One + +second_user: + id: 2 + name: Tester Two \ No newline at end of file diff --git a/vendor/plugins/userstamp/test/userstamp_test.rb b/vendor/plugins/userstamp/test/userstamp_test.rb new file mode 100644 index 0000000..666d256 --- /dev/null +++ b/vendor/plugins/userstamp/test/userstamp_test.rb @@ -0,0 +1,134 @@ +require 'abstract_unit' + +class User < ActiveRecord::Base + cattr_accessor :current_user +end + +class Entry < ActiveRecord::Base + belongs_to :created_by, :class_name => "User", :foreign_key => "created_by" + belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by" +end + +class Post < ActiveRecord::Base + record_userstamps = false +end + +class Customer < ActiveRecord::Base + cattr_accessor :current_user +end + +class UserstampTest < Test::Unit::TestCase + fixtures :users, :entries, :posts + + def setup + User.current_user = @first_user + end + + def teardown + User.current_user = nil + Entry.user_model_name = :user + end + + def test_ar_userstamp_loaded + assert ActiveRecord::Base.include?(ActiveRecord::Userstamp) + assert_equal @first_user, User.current_user + assert_equal User, @first_entry.user_model + assert_equal User, @second_entry.user_model + end + + def test_column_write_method + assert_equal @first_user, User.current_user + assert Entry.new.respond_to?("created_by=") + assert Entry.new.respond_to?("updated_by=") + + assert Post.new.respond_to?("created_by=") + assert Post.new.respond_to?("updated_by=") + end + + def test_column_read_method + assert_equal @first_user, User.current_user + assert Entry.new.respond_to?("created_by") + assert Entry.new.respond_to?("updated_by") + assert Post.new.respond_to?("created_by") + assert Post.new.respond_to?("updated_by") + end + + def test_created_by + assert_equal @first_user, User.current_user + assert_equal @first_user, @first_entry.created_by + assert_equal @second_user, @second_entry.created_by + + assert_nil @first_post.created_by + assert_nil @second_post.created_by + end + + def test_updated_by + assert_equal @first_user, User.current_user + assert_equal @first_user, @first_entry.updated_by + assert_equal @second_user, @second_entry.updated_by + + assert_nil @first_post.updated_by + assert_nil @second_post.updated_by + end + + def test_create_new + assert_equal @first_user, User.current_user, + third_user = User.create("name" => "Tester Three") + User.current_user = third_user + assert_equal third_user, User.current_user + + third_entry = Entry.create("name" => "Third Entry") + + assert_equal User, third_entry.user_model + assert_equal third_user, third_entry.created_by + assert_equal third_user, third_entry.updated_by + end + + def test_update_entry + assert_equal @first_user, User.current_user + @second_entry.update_attribute("name", "Updated by First User") + + User.current_user = @second_user + assert_equal @second_user, User.current_user + @first_entry.update_attribute("name", "Updated by Second User") + + assert_equal @first_user, @second_entry.updated_by + assert_equal @second_user, @first_entry.updated_by + end + + def test_create_and_update_entry + assert_equal @first_user, User.current_user + + third_entry = Entry.create("name" => "Third Entry") + User.current_user = @second_user + assert_equal @second_user, User.current_user + + third_entry.update_attribute("name", "Updated by Second User") + assert_equal @first_user, third_entry.created_by + assert_equal @second_user, third_entry.updated_by + end + + def test_update_with_nil_current_user + assert_equal @first_user, User.current_user + + @first_entry.update_attribute("name", "Updated by Nil") + + assert_equal @first_user, @first_entry.created_by + assert_equal @first_user, @first_entry.updated_by + end + + def test_create_with_different_user_model + assert_equal @first_user, User.current_user + Customer.current_user = @first_customer + assert_equal @first_customer, Customer.current_user + + Entry.user_model_name = :customer + third_entry = Entry.create("name" => "Customer Created Entry") + third_entry.save + + assert_equal third_entry.user_model, Customer + assert_equal third_entry.created_by, @first_customer + assert_equal third_entry.updated_by, @first_customer + end + +end -- 2.11.4.GIT