Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Version class isn't namespaced #165

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/paper_trail/has_paper_trail.rb
Expand Up @@ -39,7 +39,7 @@ def has_paper_trail(options = {})
attr_accessor self.version_association_name

class_attribute :version_class_name
self.version_class_name = options[:class_name] || 'Version'
self.version_class_name = options[:class_name] || 'PaperTrail::Version'

class_attribute :ignore
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
Expand Down
2 changes: 1 addition & 1 deletion lib/paper_trail/version.rb
@@ -1,4 +1,4 @@
class Version < ActiveRecord::Base
class PaperTrail::Version < ActiveRecord::Base
belongs_to :item, :polymorphic => true
validates_presence_of :event
attr_accessible :item_type, :item_id, :event, :whodunnit, :object, :object_changes
Expand Down
2 changes: 1 addition & 1 deletion test/dummy/app/versions/post_version.rb
@@ -1,3 +1,3 @@
class PostVersion < Version
class PostVersion < PaperTrail::Version
self.table_name = 'post_versions'
end
4 changes: 2 additions & 2 deletions test/functional/controller_test.rb
Expand Up @@ -34,7 +34,7 @@ class ControllerTest < ActionController::TestCase
assert_equal 0, w.versions.length
delete :destroy, :id => w.id
widget = assigns(:widget)
assert_equal 0, Version.with_item_keys('Widget', w.id).size
assert_equal 0, PaperTrail::Version.with_item_keys('Widget', w.id).size
end

test 'create' do
Expand Down Expand Up @@ -62,7 +62,7 @@ class ControllerTest < ActionController::TestCase
assert_equal 1, w.versions.length
delete :destroy, :id => w.id
widget = assigns(:widget)
versions_for_widget = Version.with_item_keys('Widget', w.id)
versions_for_widget = PaperTrail::Version.with_item_keys('Widget', w.id)
assert_equal 2, versions_for_widget.length
assert_equal 153, versions_for_widget.last.whodunnit.to_i
assert_equal '127.0.0.1', versions_for_widget.last.ip
Expand Down
2 changes: 1 addition & 1 deletion test/paper_trail_test.rb
Expand Up @@ -21,7 +21,7 @@ class PaperTrailTest < ActiveSupport::TestCase
widget = Widget.create
assert_equal 1, widget.versions.length
widget.destroy
versions_for_widget = Version.with_item_keys('Widget', widget.id)
versions_for_widget = PaperTrail::Version.with_item_keys('Widget', widget.id)
assert_equal 2, versions_for_widget.length
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Expand Up @@ -43,7 +43,7 @@ def change_schema
ActiveRecord::Migration.verbose = true
end

class Version < ActiveRecord::Base
class PaperTrail::Version < ActiveRecord::Base
attr_accessible :created_at, :updated_at,
:answer, :action, :question, :article_id, :ip, :user_agent
end
6 changes: 3 additions & 3 deletions test/unit/inheritance_column_test.rb
Expand Up @@ -21,19 +21,19 @@ class InheritanceColumnTest < ActiveSupport::TestCase
end

should 'work with custom STI inheritance column' do
assert_equal 12, Version.count
assert_equal 12, PaperTrail::Version.count
assert_equal 4, @animal.versions.count
assert @animal.versions.first.reify.nil?
@animal.versions[1..-1].each { |v| assert_equal 'Animal', v.reify.class.name }

# For some reason `@dog.versions` doesn't include the final `destroy` version.
# Neither do `@dog.versions.scoped` nor `@dog.versions(true)` nor `@dog.versions.reload`.
dog_versions = Version.where(:item_id => @dog.id)
dog_versions = PaperTrail::Version.where(:item_id => @dog.id)
assert_equal 4, dog_versions.count
assert dog_versions.first.reify.nil?
dog_versions[1..-1].each { |v| assert_equal 'Dog', v.reify.class.name }

cat_versions = Version.where(:item_id => @cat.id)
cat_versions = PaperTrail::Version.where(:item_id => @cat.id)
assert_equal 4, cat_versions.count
assert cat_versions.first.reify.nil?
cat_versions[1..-1].each { |v| assert_equal 'Cat', v.reify.class.name }
Expand Down
86 changes: 43 additions & 43 deletions test/unit/model_test.rb
Expand Up @@ -7,12 +7,12 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase

context 'which updates an ignored column' do
setup { @article.update_attributes :title => 'My first title' }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
end

context 'which updates an ignored column and a selected column' do
setup { @article.update_attributes :title => 'My first title', :content => 'Some text here.' }
should_change('the number of versions', :by => 1) { Version.count }
should_change('the number of versions', :by => 1) { PaperTrail::Version.count }

should 'have stored only non-ignored attributes' do
assert_equal ({'content' => [nil, 'Some text here.']}), @article.versions.last.changeset
Expand All @@ -21,22 +21,22 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase

context 'which updates a selected column' do
setup { @article.update_attributes :content => 'Some text here.' }
should_change('the number of versions', :by => 1) { Version.count }
should_change('the number of versions', :by => 1) { PaperTrail::Version.count }
end

context 'which updates a non-ignored and non-selected column' do
setup { @article.update_attributes :abstract => 'Other abstract'}
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
end

context 'which updates a skipped column' do
setup { @article.update_attributes :file_upload => 'Your data goes here' }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
end

context 'which updates a skipped column and a selected column' do
setup { @article.update_attributes :file_upload => 'Your data goes here', :content => 'Some text here.' }
should_change('the number of versions', :by => 1) { Version.count }
should_change('the number of versions', :by => 1) { PaperTrail::Version.count }

should 'have stored only non-skipped attributes' do
assert_equal ({'content' => [nil, 'Some text here.']}), @article.versions.last.changeset
Expand Down Expand Up @@ -64,7 +64,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase

context 'which updates an ignored column' do
setup { @legacy_widget.update_attributes :version => 1 }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
end
end

Expand All @@ -73,11 +73,11 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase

context 'for non-US translations' do
setup { @translation.save }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }

context 'after update' do
setup { @translation.update_attributes :content => 'Content' }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
end
end

Expand All @@ -90,22 +90,22 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
@translation.save
end

should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }

context 'after update' do
setup { @translation.update_attributes :content => 'Content' }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
end
end

context 'that are not drafts' do
setup { @translation.save }

should_change('the number of versions', :by => 1) { Version.count }
should_change('the number of versions', :by => 1) { PaperTrail::Version.count }

context 'after update' do
setup { @translation.update_attributes :content => 'Content' }
should_change('the number of versions', :by => 1) { Version.count }
should_change('the number of versions', :by => 1) { PaperTrail::Version.count }
end
end
end
Expand Down Expand Up @@ -250,15 +250,15 @@ def without(&block)
setup do
@fluxor = @widget.fluxors.create :name => 'flux'
@widget.destroy
@reified_widget = Version.last.reify
@reified_widget = PaperTrail::Version.last.reify
end

should 'record the correct event' do
assert_match /destroy/i, Version.last.event
assert_match /destroy/i, PaperTrail::Version.last.event
end

should 'have three previous versions' do
assert_equal 3, Version.with_item_keys('Widget', @widget.id).length
assert_equal 3, PaperTrail::Version.with_item_keys('Widget', @widget.id).length
end

should 'be available in its previous version' do
Expand Down Expand Up @@ -488,7 +488,7 @@ def without(&block)
setup do
PaperTrail.whodunnit = 'Charlie'
@widget.destroy
@version = Version.last
@version = PaperTrail::Version.last
end

should 'track who made the change' do
Expand All @@ -510,20 +510,20 @@ def without(&block)
end

should 'reify with the correct type' do
thing = Version.last.reify
thing = PaperTrail::Version.last.reify
assert_kind_of FooWidget, thing
assert_equal @foo.versions.first, Version.last.previous
assert_nil Version.last.next
assert_equal @foo.versions.first, PaperTrail::Version.last.previous
assert_nil PaperTrail::Version.last.next
end

context 'when destroyed' do
setup { @foo.destroy }

should 'reify with the correct type' do
thing = Version.last.reify
thing = PaperTrail::Version.last.reify
assert_kind_of FooWidget, thing
assert_equal @foo.versions[1], Version.last.previous
assert_nil Version.last.next
assert_equal @foo.versions[1], PaperTrail::Version.last.previous
assert_nil PaperTrail::Version.last.next
end
end
end
Expand Down Expand Up @@ -762,35 +762,35 @@ def without(&block)
end

should 'store version on source <<' do
count = Version.count
count = PaperTrail::Version.count
@book.authors << @dostoyevsky
assert_equal 1, Version.count - count
assert_equal Version.last, @book.authorships.first.versions.first
assert_equal 1, PaperTrail::Version.count - count
assert_equal PaperTrail::Version.last, @book.authorships.first.versions.first
end

should 'store version on source create' do
count = Version.count
count = PaperTrail::Version.count
@book.authors.create :name => 'Tolstoy'
assert_equal 2, Version.count - count
assert_same_elements [Person.last, Authorship.last], [Version.all[-2].item, Version.last.item]
assert_equal 2, PaperTrail::Version.count - count
assert_same_elements [Person.last, Authorship.last], [PaperTrail::Version.all[-2].item, PaperTrail::Version.last.item]
end

should 'store version on join destroy' do
@book.authors << @dostoyevsky
count = Version.count
count = PaperTrail::Version.count
@book.authorships(true).last.destroy
assert_equal 1, Version.count - count
assert_equal @book, Version.last.reify.book
assert_equal @dostoyevsky, Version.last.reify.person
assert_equal 1, PaperTrail::Version.count - count
assert_equal @book, PaperTrail::Version.last.reify.book
assert_equal @dostoyevsky, PaperTrail::Version.last.reify.person
end

should 'store version on join clear' do
@book.authors << @dostoyevsky
count = Version.count
count = PaperTrail::Version.count
@book.authorships(true).clear
assert_equal 1, Version.count - count
assert_equal @book, Version.last.reify.book
assert_equal @dostoyevsky, Version.last.reify.person
assert_equal 1, PaperTrail::Version.count - count
assert_equal @book, PaperTrail::Version.last.reify.book
assert_equal @dostoyevsky, PaperTrail::Version.last.reify.person
end
end

Expand Down Expand Up @@ -876,17 +876,17 @@ def without(&block)
end
end

context 'A new model instance which uses a custom Version class' do
context 'A new model instance which uses a custom PaperTrail::Version class' do
setup { @post = Post.new }

context 'which is then saved' do
setup { @post.save }
should_change('the number of post versions') { PostVersion.count }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
end
end

context 'An existing model instance which uses a custom Version class' do
context 'An existing model instance which uses a custom PaperTrail::Version class' do
setup { @post = Post.create }

context 'on the first version' do
Expand All @@ -904,7 +904,7 @@ def without(&block)
context 'which is modified' do
setup { @post.update_attributes({ :content => "Some new content" }) }
should_change('the number of post versions') { PostVersion.count }
should_not_change('the number of versions') { Version.count }
should_not_change('the number of versions') { PaperTrail::Version.count }
should "not have stored changes when object_changes column doesn't exist" do
assert_nil @post.versions.last.changeset
end
Expand Down Expand Up @@ -1050,9 +1050,9 @@ def without(&block)
# Updates `model`'s last version so it looks like the version was
# created 2 seconds ago.
def make_last_version_earlier(model)
Version.record_timestamps = false
PaperTrail::Version.record_timestamps = false
model.versions.last.update_attributes :created_at => 2.seconds.ago
Version.record_timestamps = true
PaperTrail::Version.record_timestamps = true
end

end
2 changes: 1 addition & 1 deletion test/unit/timestamp_test.rb
Expand Up @@ -5,7 +5,7 @@ class TimestampTest < ActiveSupport::TestCase
setup do
PaperTrail.timestamp_field = :custom_created_at
change_schema
Version.reset_column_information
PaperTrail::Version.reset_column_information

Fluxor.instance_eval <<-END
has_paper_trail
Expand Down
18 changes: 9 additions & 9 deletions test/unit/version_test.rb
Expand Up @@ -4,38 +4,38 @@ class VersionTest < ActiveSupport::TestCase
setup {
change_schema
@article = Animal.create
assert Version.creates.present?
assert PaperTrail::Version.creates.present?
}

context "Version.creates" do
context "PaperTrail::Version.creates" do
should "return only create events" do
Version.creates.each do |version|
PaperTrail::Version.creates.each do |version|
assert_equal "create", version.event
end
end
end

context "Version.updates" do
context "PaperTrail::Version.updates" do
setup {
@article.update_attributes(:name => 'Animal')
assert Version.updates.present?
assert PaperTrail::Version.updates.present?
}

should "return only update events" do
Version.updates.each do |version|
PaperTrail::Version.updates.each do |version|
assert_equal "update", version.event
end
end
end

context "Version.destroys" do
context "PaperTrail::Version.destroys" do
setup {
@article.destroy
assert Version.destroys.present?
assert PaperTrail::Version.destroys.present?
}

should "return only destroy events" do
Version.destroys.each do |version|
PaperTrail::Version.destroys.each do |version|
assert_equal "destroy", version.event
end
end
Expand Down