Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new(:spec)

task :default => :spec

if RUBY_VERSION < '1.9'
desc "Run all tests with coverage"
RSpec::Core::RakeTask.new :coverage => :cleanup_coverage_files do |t|
Expand Down
3 changes: 2 additions & 1 deletion lib/vestal_versions/creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ module InstanceMethods
private
# Returns whether an initial version should be created upon creation of the parent record.
def create_initial_version?
vestal_versions_options[:initial_version] == true
vestal_versions_options[:initial_version] == true &&
version_conditions_met?
end

# Creates an initial version upon creation of the parent record.
Expand Down
3 changes: 2 additions & 1 deletion lib/vestal_versions/deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ module InstanceMethods
private

def delete_version?
vestal_versions_options[:track_destroy]
vestal_versions_options[:track_destroy] &&
version_conditions_met?
end

def create_destroyed_version
Expand Down
2 changes: 1 addition & 1 deletion lib/vestal_versions/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def prepare_versioned_options(options)
# :order => "#{options[:class_name].constantize.table_name}.#{connection.quote_column_name('number')} ASC"
# )

class_inheritable_accessor :vestal_versions_options
class_attribute :vestal_versions_options
self.vestal_versions_options = options.dup

options.merge!(
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
end
end

Dir[File.dirname(__FILE__) + '/support/*.rb'].each { |f| require f }
Dir[File.expand_path('../support/*.rb', __FILE__)].each{|f| require f }
9 changes: 9 additions & 0 deletions spec/vestal_versions/creation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
its('versions.count'){ should == 1 }
end

context "with :initial_version and false conditional options" do
before do
User.prepare_versioned_options(:initial_version => true,
:if => Proc.new { false })
end

its('versions.count'){ should == 0 }
end

it 'does not increase when no changes are made in an update' do
expect {
subject.update_attribute(:name, name)
Expand Down
20 changes: 20 additions & 0 deletions spec/vestal_versions/deletion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@
VestalVersions::Version.last.tag.should == 'deleted'
end

context "when conditions aren't met" do
before do
DeletedUser.prepare_versioned_options(:dependent => :tracking,
:if => Proc.new { false })
end

after do
DeletedUser.prepare_versioned_options(:dependent => :tracking)
end

it "removes the original record" do
subject.destroy

DeletedUser.find_by_id(subject.id).should be_nil
end

it "doesn't create a version" do
expect{ subject.destroy }.to_not change{ VestalVersions::Version.count }
end
end
end

context "deleted versions" do
Expand Down