Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 24 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 27, 2012
@shayfrendt shayfrendt Fix Rails 3.2 deprecation for set_table_name 587a47a
@shayfrendt shayfrendt Fix Rails 3.2 deprecation for class_inheritable_hash 12aced7
Commits on Apr 29, 2012
@shayfrendt shayfrendt Fix Rails 3.2 deprecation for named_scope 4b7f3d1
Commits on Jun 28, 2012
@shayfrendt shayfrendt Bump gem to Rails 3.2
- Move to Bundler for dependency management
- Drop support for RDoc
- Upgrade to rspec 2
- Clean up a bunch of whitespace
- Add a Guardfile for easy testing
d4bfaf3
View
1  .rvmrc
@@ -0,0 +1 @@
+rvm 1.9.3-p194@acts_as_revisable
View
4 Gemfile
@@ -0,0 +1,4 @@
+source :rubygems
+
+# Gem dependencies specified in acts_as_revisable.gemspec
+gemspec
View
66 Gemfile.lock
@@ -0,0 +1,66 @@
+PATH
+ remote: .
+ specs:
+ acts_as_revisable (1.2.0)
+ activerecord (>= 3.2.3)
+ activesupport (>= 3.2.3)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.2.6)
+ activesupport (= 3.2.6)
+ builder (~> 3.0.0)
+ activerecord (3.2.6)
+ activemodel (= 3.2.6)
+ activesupport (= 3.2.6)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activesupport (3.2.6)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ diff-lcs (1.1.3)
+ ffi (1.0.11)
+ growl (1.0.3)
+ guard (1.2.1)
+ listen (>= 0.4.2)
+ thor (>= 0.14.6)
+ guard-rspec (1.1.0)
+ guard (>= 1.1)
+ i18n (0.6.0)
+ listen (0.4.7)
+ rb-fchange (~> 0.0.5)
+ rb-fsevent (~> 0.9.1)
+ rb-inotify (~> 0.8.8)
+ multi_json (1.3.6)
+ rake (0.9.2.2)
+ rb-fchange (0.0.5)
+ ffi
+ rb-fsevent (0.9.1)
+ rb-inotify (0.8.8)
+ ffi (>= 0.5.0)
+ rspec (2.10.0)
+ rspec-core (~> 2.10.0)
+ rspec-expectations (~> 2.10.0)
+ rspec-mocks (~> 2.10.0)
+ rspec-core (2.10.1)
+ rspec-expectations (2.10.0)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.10.1)
+ sqlite3 (1.3.6)
+ thor (0.15.3)
+ tzinfo (0.3.33)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ acts_as_revisable!
+ growl (~> 1.0.3)
+ guard-rspec (~> 1.1.0)
+ rake (~> 0.9.2)
+ rb-fsevent (~> 0.9.1)
+ rspec (~> 2.10.0)
+ sqlite3 (~> 1.3.6)
View
14 Guardfile
@@ -0,0 +1,14 @@
+# Run me with:
+#
+# $ bundle exec guard
+
+begin
+ require 'rb-inotify'
+ require 'libnotify'
+rescue LoadError
+end
+
+guard 'rspec', :all_on_start => false, :all_after_pass => false do
+ watch(%r{^spec/.+_spec\.rb})
+ watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+end
View
47 Rakefile
@@ -1,44 +1,9 @@
-require 'rake/rdoctask'
-require 'rake/gempackagetask'
-require 'fileutils'
-require 'lib/acts_as_revisable/version'
-require 'lib/acts_as_revisable/gem_spec_options'
+require 'bundler'
+Bundler::GemHelper.install_tasks
+require 'rspec/core/rake_task'
-Rake::RDocTask.new do |rdoc|
- files = ['README.rdoc','LICENSE','lib/**/*.rb','doc/**/*.rdoc','spec/*.rb']
- rdoc.rdoc_files.add(files)
- rdoc.main = 'README.rdoc'
- rdoc.title = 'acts_as_revisable RDoc'
- rdoc.rdoc_dir = 'doc'
- rdoc.options << '--line-numbers' << '--inline-source'
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = FileList['spec/**/*_spec.rb']
end
-spec = Gem::Specification.new do |s|
- WithoutScope::ActsAsRevisable::GemSpecOptions::HASH.each do |key, value|
- s.send("#{key.to_s}=",value)
- end
-end
-
-Rake::GemPackageTask.new(spec) do |package|
- package.gem_spec = spec
-end
-
-desc "Generate the static gemspec required for github."
-task :generate_gemspec do
- options = WithoutScope::ActsAsRevisable::GemSpecOptions::HASH.clone
- options[:name] = "acts_as_revisable"
-
- spec = ["Gem::Specification.new do |s|"]
- options.each do |key, value|
- spec << " s.#{key.to_s} = #{value.inspect}"
- end
- spec << "end"
-
- open("acts_as_revisable.gemspec", "w").write(spec.join("\n"))
-end
-
-desc "Install acts_as_revisable"
-task :install => :repackage do
- options = WithoutScope::ActsAsRevisable::GemSpecOptions::HASH.clone
- sh %{sudo gem install pkg/#{options[:name]}-#{spec.version} --no-rdoc --no-ri}
-end
+task :default => :spec
View
44 acts_as_revisable.gemspec
@@ -1,12 +1,34 @@
+# -*- encoding: utf-8 -*-
+lib = File.expand_path('../lib/', __FILE__)
+$:.unshift lib unless $:.include?(lib)
+
+require 'acts_as_revisable/version'
+
Gem::Specification.new do |s|
- s.summary = "acts_as_revisable enables revision tracking, querying, reverting and branching of ActiveRecord models. Inspired by acts_as_versioned."
- s.has_rdoc = true
- s.files = ["LICENSE", "README.rdoc", "Rakefile", "spec/associations_spec.rb", "spec/branch_spec.rb", "spec/deletable_spec.rb", "spec/find_spec.rb", "spec/general_spec.rb", "spec/options_spec.rb", "spec/quoted_columns_spec.rb", "spec/revert_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/sti_spec.rb", "spec/validations_spec.rb", "lib/acts_as_revisable", "lib/acts_as_revisable/acts", "lib/acts_as_revisable/acts/common.rb", "lib/acts_as_revisable/acts/deletable.rb", "lib/acts_as_revisable/acts/revisable.rb", "lib/acts_as_revisable/acts/revision.rb", "lib/acts_as_revisable/base.rb", "lib/acts_as_revisable/gem_spec_options.rb", "lib/acts_as_revisable/options.rb", "lib/acts_as_revisable/quoted_columns.rb", "lib/acts_as_revisable/validations.rb", "lib/acts_as_revisable/version.rb", "lib/acts_as_revisable.rb", "generators/revisable_migration", "generators/revisable_migration/revisable_migration_generator.rb", "generators/revisable_migration/templates", "generators/revisable_migration/templates/migration.rb", "rails/init.rb"]
- s.email = "rich@withoutscope.com"
- s.rdoc_options = ["--main", "README.rdoc"]
- s.version = "1.1.1"
- s.homepage = "http://github.com/rich/acts_as_revisable"
- s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
- s.name = "acts_as_revisable"
- s.authors = ["Rich Cavanaugh", "Stephen Caudill"]
-end
+ s.name = "acts_as_revisable"
+ s.version = WithoutScope::ActsAsRevisable::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.date = "2012-06-28"
+ s.authors = ["Rich Cavanaugh", "Stephen Caudill"]
+ s.email = "rich@withoutscope.com"
+ s.homepage = "http://github.com/chargify/acts_as_revisable"
+ s.summary = "acts_as_revisable enables revision tracking, querying, reverting and branching of ActiveRecord models. Inspired by acts_as_versioned."
+
+ s.required_rubygems_version = ">= 1.3.6"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.require_paths = ['lib']
+
+ # Runtime Dependencies
+ s.add_runtime_dependency('activesupport', '>= 3.2.3')
+ s.add_runtime_dependency('activerecord', '>= 3.2.3')
+
+ # Development Dependencies
+ s.add_development_dependency('rake', '~> 0.9.2')
+ s.add_development_dependency('rspec', '~> 2.10.0')
+ s.add_development_dependency('guard-rspec', '~> 1.1.0')
+ s.add_development_dependency('growl', '~> 1.0.3')
+ s.add_development_dependency('rb-fsevent', '~> 0.9.1')
+ s.add_development_dependency('sqlite3', '~> 1.3.6')
+end
View
8 lib/acts_as_revisable.rb
@@ -1,8 +1,6 @@
-$:.unshift(File.dirname(__FILE__)) unless
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-
-require 'activesupport' unless defined? ActiveSupport
-require 'activerecord' unless defined? ActiveRecord
+require 'rubygems'
+require 'active_support' unless defined? ActiveSupport
+require 'active_record' unless defined? ActiveRecord
require 'acts_as_revisable/version.rb'
require 'acts_as_revisable/base'
View
6 lib/acts_as_revisable/acts/common.rb
@@ -12,10 +12,10 @@ module Common
def self.included(base) #:nodoc:
base.send(:extend, ClassMethods)
- base.class_inheritable_hash :revisable_after_callback_blocks
+ base.class_attribute :revisable_after_callback_blocks
base.revisable_after_callback_blocks = {}
- base.class_inheritable_hash :revisable_current_states
+ base.class_attribute :revisable_current_states
base.revisable_current_states = {}
base.instance_eval do
@@ -217,4 +217,4 @@ def instantiate(record) #:nodoc:
end
end
end
-end
+end
View
138 lib/acts_as_revisable/acts/revisable.rb
@@ -1,6 +1,6 @@
module WithoutScope
module ActsAsRevisable
-
+
# This module is mixed into the revision classes.
#
# ==== Callbacks
@@ -16,26 +16,26 @@ module ActsAsRevisable
module Revisable
def self.included(base) #:nodoc:
base.send(:extend, ClassMethods)
-
+
class << base
attr_accessor :revisable_revision_class, :revisable_columns
end
-
- base.class_inheritable_hash :revisable_shared_objects
+
+ base.class_attribute :revisable_shared_objects
base.revisable_shared_objects = {}
-
+
base.instance_eval do
attr_accessor :revisable_new_params, :revisable_revision
-
+
define_callbacks :before_revise, :after_revise, :before_revert, :after_revert, :before_changeset, :after_changeset, :after_branch_created
-
+
before_create :before_revisable_create
before_update :before_revisable_update
after_update :after_revisable_update
after_save :clear_revisable_shared_objects!, :unless => :is_reverting?
-
+
default_scope :conditions => {:revisable_is_current => true}
-
+
[:revisions, revisions_association_name.to_sym].each do |assoc|
has_many assoc, (revisable_options.revision_association_options || {}).merge({:class_name => revision_class_name, :foreign_key => :revisable_original_id, :order => "#{quoted_table_name}.#{connection.quote_column_name(:revisable_number)} DESC", :dependent => :destroy})
end
@@ -47,7 +47,7 @@ class << base
end
end
end
-
+
# Finds a specific revision of self.
#
# The +by+ parameter can be a revision_class instance,
@@ -69,7 +69,7 @@ class << base
# revision_number.
def find_revision(by)
by = Integer(by) if by.is_a?(String) && by.match(/[0-9]+/)
-
+
case by
when self.class
by
@@ -87,7 +87,7 @@ def find_revision(by)
revisions.find_by_revisable_number(by)
end
end
-
+
# Returns a revisable_class instance initialized with the record
# found using find_revision.
#
@@ -106,28 +106,28 @@ def find_revision(by)
# * +after_revise+ is called after the record is revised.
def revert_to(what, *args, &block) #:yields:
is_reverting!
-
+
unless run_callbacks(:before_revert) { |r, o| r == false}
raise ActiveRecord::RecordNotSaved
end
-
+
options = args.extract_options!
-
+
rev = find_revision(what)
self.reverting_to, self.reverting_from = rev, self
-
+
unless rev.run_callbacks(:before_restore) { |r, o| r == false}
raise ActiveRecord::RecordNotSaved
end
-
+
self.class.column_names.each do |col|
next unless self.class.revisable_should_clone_column? col
self[col] = rev[col]
end
-
+
self.no_revision! if options.delete :without_revision
self.revisable_new_params = options
-
+
yield(self) if block_given?
rev.run_callbacks(:after_restore)
run_callbacks(:after_revert)
@@ -136,14 +136,14 @@ def revert_to(what, *args, &block) #:yields:
is_reverting!(false)
clear_revisable_shared_objects!
end
-
+
# Same as revert_to except it also saves the record.
def revert_to!(what, *args)
revert_to(what, *args) do
self.no_revision? ? save! : revise!
end
end
-
+
# Equivalent to:
# revert_to(:without_revision => true)
def revert_to_without_revision(*args)
@@ -151,7 +151,7 @@ def revert_to_without_revision(*args)
options.update({:without_revision => true})
revert_to(*(args << options))
end
-
+
# Equivalent to:
# revert_to!(:without_revision => true)
def revert_to_without_revision!(*args)
@@ -159,38 +159,38 @@ def revert_to_without_revision!(*args)
options.update({:without_revision => true})
revert_to!(*(args << options))
end
-
+
# Globally sets the reverting state of this record.
def is_reverting!(val=true) #:nodoc:
set_revisable_state(:reverting, val)
end
-
+
# Returns true if the _record_ (not just this instance
# of the record) is currently being reverted.
def is_reverting?
get_revisable_state(:reverting) || false
end
-
+
# Sets whether or not to force a revision.
def force_revision!(val=true) #:nodoc:
set_revisable_state(:force_revision, val)
end
-
+
# Returns true if a revision should be forced.
def force_revision? #:nodoc:
get_revisable_state(:force_revision) || false
end
-
+
# Sets whether or not a revision should be created.
def no_revision!(val=true) #:nodoc:
set_revisable_state(:no_revision, val)
end
-
+
# Returns true if no revision should be created.
def no_revision? #:nodoc:
get_revisable_state(:no_revision) || false
end
-
+
# Force an immediate revision whether or
# not any columns have been modified.
#
@@ -204,7 +204,7 @@ def no_revision? #:nodoc:
# * +after_revise+ is called after the record is revised.
def revise!(*args)
return if in_revision?
-
+
begin
force_revision!
in_revision!
@@ -214,12 +214,12 @@ def revise!(*args)
force_revision!(false)
end
end
-
+
# Groups statements that could trigger several revisions into
# a single revision. The revision is created once #save is called.
- #
+ #
# ==== Example
- #
+ #
# @project.revision_number # => 1
# @project.changeset do |project|
# # each one of the following statements would
@@ -237,17 +237,17 @@ def revise!(*args)
# * +after_changeset+ is called after a changeset block is called.
def changeset(&block)
return unless block_given?
-
+
return yield(self) if in_revision?
-
+
unless run_callbacks(:before_changeset) { |r, o| r == false}
raise ActiveRecord::RecordNotSaved
end
-
+
begin
force_revision!
in_revision!
-
+
returning(yield(self)) do
run_callbacks(:after_changeset)
end
@@ -255,7 +255,7 @@ def changeset(&block)
in_revision!(false)
end
end
-
+
# Same as +changeset+ except it also saves the record.
def changeset!(&block)
changeset do
@@ -263,10 +263,10 @@ def changeset!(&block)
save!
end
end
-
+
def without_revisions!
return if in_revision? || !block_given?
-
+
begin
no_revision!
in_revision!
@@ -277,27 +277,27 @@ def without_revisions!
no_revision!(false)
end
end
-
+
# acts_as_revisable's override for ActiveRecord::Base's #save!
def save!(*args) #:nodoc:
self.revisable_new_params ||= args.extract_options!
self.no_revision! if self.revisable_new_params.delete :without_revision
super
end
-
- # acts_as_revisable's override for ActiveRecord::Base's #save
+
+ # acts_as_revisable's override for ActiveRecord::Base's #save
def save(*args) #:nodoc:
self.revisable_new_params ||= args.extract_options!
self.no_revision! if self.revisable_new_params.delete :without_revision
super(args)
end
-
+
# Set some defaults for a newly created +Revisable+ instance.
def before_revisable_create #:nodoc:
self[:revisable_is_current] = true
self.revision_number ||= 0
end
-
+
# Checks whether or not a +Revisable+ should be revised.
def should_revise? #:nodoc:
return false if new_record?
@@ -306,22 +306,22 @@ def should_revise? #:nodoc:
return false unless self.changed?
!(self.changed.map(&:downcase) & self.class.revisable_watch_columns).blank?
end
-
+
# Checks whether or not a revision should be stored.
# If it should be, it initialized the revision_class
# and stores it in an accessor for later saving.
def before_revisable_update #:nodoc:
return unless should_revise?
in_revision!
-
+
unless run_callbacks(:before_revise) { |r, o| r == false}
in_revision!(false)
return false
end
-
+
self.revisable_revision = self.to_revision
end
-
+
# Checks if an initialized revision_class has been stored
# in the accessor. If it has been, this instance is saved.
def after_revisable_update #:nodoc:
@@ -337,7 +337,7 @@ def after_revisable_update #:nodoc:
force_revision!(false)
true
end
-
+
# Returns true if the _record_ (not just this instance
# of the record) is currently being revised.
def in_revision?
@@ -350,18 +350,18 @@ def in_revision?
def in_revision!(val=true) #:nodoc:
set_revisable_state(:revision, val)
end
-
+
# This returns a new +Revision+ instance with all the appropriate
# values initialized.
def to_revision #:nodoc:
rev = self.class.revision_class.new(self.revisable_new_params)
rev.revisable_original_id = self.id
-
+
new_revision_number = revisions.maximum(:revisable_number) + 1 rescue self.revision_number
rev.revision_number = new_revision_number
self.revision_number = new_revision_number + 1
-
+
self.class.column_names.each do |col|
next unless self.class.revisable_should_clone_column? col
val = self.send("#{col}_changed?") ? self.send("#{col}_was") : self.send(col)
@@ -372,29 +372,29 @@ def to_revision #:nodoc:
rev
end
-
+
# This returns
def current_revision
self
end
-
+
def for_revision
key = self.read_attribute(self.class.primary_key)
self.class.revisable_shared_objects[key] ||= {}
end
-
+
def reverting_to
for_revision[:reverting_to]
end
-
+
def reverting_to=(val)
for_revision[:reverting_to] = val
end
-
+
def reverting_from
for_revision[:reverting_from]
end
-
+
def reverting_from=(val)
for_revision[:reverting_from] = val
end
@@ -403,7 +403,7 @@ def clear_revisable_shared_objects!
key = self.read_attribute(self.class.primary_key)
self.class.revisable_shared_objects.delete(key)
end
-
+
module ClassMethods
# acts_as_revisable's override for with_scope that allows for
# including revisions in the scope.
@@ -424,7 +424,7 @@ def with_scope(*args, &block) #:nodoc:
super(*args, &block)
end
end
-
+
# acts_as_revisable's override for find that allows for
# including revisions in the find.
#
@@ -433,7 +433,7 @@ def with_scope(*args, &block) #:nodoc:
# find(:all, :with_revisions => true)
def find(*args) #:nodoc:
options = args.grep(Hash).first
-
+
if options && options.delete(:with_revisions)
with_exclusive_scope do
super(*args)
@@ -442,36 +442,36 @@ def find(*args) #:nodoc:
super(*args)
end
end
-
+
# Returns the +revision_class_name+ as configured in
# +acts_as_revisable+.
def revision_class_name #:nodoc:
self.revisable_options.revision_class_name || "#{self.name}Revision"
end
-
+
# Returns the actual +Revision+ class based on the
# #revision_class_name.
def revision_class #:nodoc:
self.revisable_revision_class ||= self.revision_class_name.constantize
end
-
+
# Returns the revisable_class which in this case is simply +self+.
def revisable_class #:nodoc:
self
end
-
+
# Returns the name of the association acts_as_revisable
# creates.
def revisions_association_name #:nodoc:
revision_class_name.pluralize.underscore
end
-
+
# Returns an Array of the columns that are watched for changes.
def revisable_watch_columns #:nodoc:
return self.revisable_columns unless self.revisable_columns.blank?
return self.revisable_columns ||= [] if self.revisable_options.except == :all
return self.revisable_columns ||= [self.revisable_options.only].flatten.map(&:to_s).map(&:downcase) unless self.revisable_options.only.blank?
-
+
except = [self.revisable_options.except].flatten || []
except += REVISABLE_SYSTEM_COLUMNS
except += REVISABLE_UNREVISABLE_COLUMNS
@@ -482,4 +482,4 @@ def revisable_watch_columns #:nodoc:
end
end
end
-end
+end
View
6 lib/acts_as_revisable/acts/revision.rb
@@ -17,14 +17,14 @@ class << base
end
base.instance_eval do
- set_table_name(revisable_class.table_name)
+ self.table_name = revisable_class.table_name
default_scope :conditions => {:revisable_is_current => false}
define_callbacks :before_restore, :after_restore
before_create :revision_setup
after_create :grab_my_branches
- named_scope :deleted, :conditions => ["? is not null", :revisable_deleted_at]
+ scope :deleted, :conditions => ["? is not null", :revisable_deleted_at]
[:current_revision, revisable_association_name.to_sym].each do |a|
belongs_to a, :class_name => revisable_class_name, :foreign_key => :revisable_original_id
@@ -145,4 +145,4 @@ def revision_cloned_associations #:nodoc:
end
end
end
-end
+end
View
10 lib/acts_as_revisable/version.rb
@@ -1,11 +1,5 @@
-module WithoutScope #:nodoc:
+module WithoutScope
module ActsAsRevisable
- module VERSION #:nodoc:
- MAJOR = 1
- MINOR = 1
- TINY = 1
-
- STRING = [MAJOR, MINOR, TINY].join('.')
- end
+ VERSION = "1.2.0"
end
end
View
1  rails/init.rb
@@ -1 +0,0 @@
-require 'acts_as_revisable'
View
10 spec/associations_spec.rb → spec/acts_as_revisable/associations_spec.rb
@@ -1,22 +1,22 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe WithoutScope::ActsAsRevisable do
after(:each) do
cleanup_db
end
-
+
before(:each) do
@project = Project.create(:name => "Rich", :notes => "this plugin's author")
@project.update_attribute(:name, "one")
@project.update_attribute(:name, "two")
@project.update_attribute(:name, "three")
end
-
+
it "should have a pretty named association" do
lambda { @project.sessions }.should_not raise_error
end
-
+
it "should return all the revisions" do
@project.revisions.size.should == 3
end
-end
+end
View
22 spec/branch_spec.rb → spec/acts_as_revisable/branch_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
class Project
validates_presence_of :name
@@ -8,47 +8,47 @@ class Project
after(:each) do
cleanup_db
end
-
+
before(:each) do
@project = Project.create(:name => "Rich", :notes => "a note")
@project.update_attribute(:name, "Sam")
end
-
+
it "should allow for branch creation" do
@project.should == @project.branch.branch_source
end
-
+
it "should always tie the branch to the correct version" do
b = @project.branch!
@project.revise!
prev = @project.find_revision(:last)
b.reload.branch_source.should == prev
end
-
+
it "should have branches" do
b = @project.branch!
@project.branches.size.should == 1
end
-
+
it "should branch without saving" do
@project.branch.should be_new_record
end
-
+
it "should branch and save" do
@project.branch!.should_not be_new_record
end
-
+
it "should not raise an error for a valid branch" do
lambda { @project.branch!(:name => "A New User") }.should_not raise_error
end
-
+
it "should raise an error for invalid records" do
lambda { @project.branch!(:name => nil) }.should raise_error
end
-
+
it "should not save an invalid record" do
@branch = @project.branch(:name => nil)
@branch.save.should be_false
@branch.should be_new_record
end
-end
+end
View
4 spec/deletable_spec.rb → spec/acts_as_revisable/deletable_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe WithoutScope::ActsAsRevisable::Deletable do
after(:each) do
@@ -13,4 +13,4 @@
it "should store a revision on destroy" do
lambda{ @person.destroy }.should change(OldPerson, :count).from(1).to(2)
end
-end
+end
View
4 spec/find_spec.rb → spec/acts_as_revisable/find_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe WithoutScope::ActsAsRevisable do
after(:each) do
@@ -31,4 +31,4 @@
@project1.find_revision(:last).should == @project1.find_revision(:previous)
end
end
-end
+end
View
2  spec/general_spec.rb → spec/acts_as_revisable/general_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe WithoutScope::ActsAsRevisable do
after(:each) do
View
4 spec/options_spec.rb → spec/acts_as_revisable/options_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
shared_examples_for "common Options usage" do
it "should return a set value" do
@@ -80,4 +80,4 @@
it_should_behave_like "common Options usage"
end
end
-end
+end
View
4 spec/quoted_columns_spec.rb → spec/acts_as_revisable/quoted_columns_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe "the quoted_columns extension" do
after(:each) do
@@ -16,4 +16,4 @@
it "should not quote strings any differently" do
Project.send(:quote_bound_value, "what").should == ActiveRecord::Base.send(:quote_bound_value, "what")
end
-end
+end
View
4 spec/revert_spec.rb → spec/acts_as_revisable/revert_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe WithoutScope::ActsAsRevisable, "with reverting" do
after(:each) do
@@ -39,4 +39,4 @@
lambda{ @project.revert_to(:first) }.should_not raise_error
@project.should be_changed
end
-end
+end
View
4 spec/sti_spec.rb → spec/acts_as_revisable/sti_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe WithoutScope::ActsAsRevisable, "with single table inheritance" do
after(:each) do
@@ -39,4 +39,4 @@
Post.find_by_name('a post').should_not be_nil
end
end
-end
+end
View
4 spec/validations_spec.rb → spec/acts_as_revisable/validations_spec.rb
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/spec_helper.rb'
+require 'spec_helper'
describe WithoutScope::ActsAsRevisable, "with validations" do
after(:each) do
@@ -22,4 +22,4 @@
lambda {@foo.revise!; @foo.revise!}.should raise_error
end
end
-end
+end
View
1  spec/spec.opts
@@ -1 +0,0 @@
---colour
View
47 spec/spec_helper.rb
@@ -1,22 +1,25 @@
-begin
- require 'spec'
-rescue LoadError
- require 'rubygems'
- gem 'rspec'
- require 'spec'
-end
-
-if ENV['EDGE_RAILS_PATH']
- edge_path = File.expand_path(ENV['EDGE_RAILS_PATH'])
- require File.join(edge_path, 'activesupport', 'lib', 'active_support')
- require File.join(edge_path, 'activerecord', 'lib', 'active_record')
-end
+$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
-$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'acts_as_revisable'
+require 'rspec'
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
+RSpec.configure do |config|
+ config.filter_run :focused => true
+ config.run_all_when_everything_filtered = true
+ config.alias_example_to :fit, :focused => true
+ config.alias_example_to :xit, :disabled => true
+ config.color_enabled = true
+
+ # so we can use `:vcr` rathaner than `:vcr => true`;
+ # in RSpec 3 this will no longer be necessary.
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+
+ config.before(:all) do
+ end
+end
+
def setup_db
ActiveRecord::Schema.define(:version => 1) do
create_table :people do |t|
@@ -27,7 +30,7 @@ def setup_db
t.datetime :revisable_current_at, :revisable_revised_at, :revisable_deleted_at
t.timestamps
end
-
+
create_table :projects do |t|
t.string :name, :unimportant, :revisable_name, :revisable_type
t.text :notes
@@ -36,7 +39,7 @@ def setup_db
t.datetime :revisable_current_at, :revisable_revised_at, :revisable_deleted_at
t.timestamps
end
-
+
create_table :foos do |t|
t.string :name, :revisable_name, :revisable_type
t.text :notes
@@ -45,7 +48,7 @@ def setup_db
t.datetime :revisable_current_at, :revisable_revised_at, :revisable_deleted_at
t.timestamps
end
-
+
create_table :posts do |t|
t.string :name, :revisable_name, :revisable_type, :type
t.boolean :revisable_is_current
@@ -66,7 +69,7 @@ def cleanup_db
class Person < ActiveRecord::Base
belongs_to :project
-
+
acts_as_revisable do
revision_class_name "OldPerson"
on_delete :revise
@@ -82,7 +85,7 @@ class OldPerson < ActiveRecord::Base
class Project < ActiveRecord::Base
has_many :people
-
+
acts_as_revisable do
revision_class_name "Session"
except :unimportant
@@ -98,13 +101,13 @@ class Session < ActiveRecord::Base
class Foo < ActiveRecord::Base
acts_as_revisable :generate_revision_class => true, :no_validation_scoping => true
-
+
validates_uniqueness_of :name
end
class Post < ActiveRecord::Base
acts_as_revisable
-
+
validates_uniqueness_of :name
end
@@ -118,4 +121,4 @@ class Article < Post
class ArticleRevision < PostRevision
acts_as_revision
-end
+end

No commit comments for this range

Something went wrong with that request. Please try again.