mirror of
https://github.com/paper-trail-gem/paper_trail.git
synced 2022-11-09 11:33:19 -05:00
Use RSpec 3 for testing; Update syntax in spec suite for RSpec 3
This commit is contained in:
parent
838b0df836
commit
716c3e0fb5
15 changed files with 268 additions and 197 deletions
2
.rspec
2
.rspec
|
@ -1,2 +1,2 @@
|
|||
--format progress
|
||||
--color
|
||||
--require spec_helper
|
||||
|
|
|
@ -15,7 +15,7 @@ group :development, :test do
|
|||
gem 'rack-test', '>= 0.6'
|
||||
|
||||
# RSpec testing
|
||||
gem 'rspec-rails', '~> 2.14'
|
||||
gem 'rspec-rails', '~> 3.1.0'
|
||||
gem 'generator_spec'
|
||||
|
||||
# To do proper transactional testing with ActiveSupport::TestCase on MySQL
|
||||
|
|
|
@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency 'railties', ['>= 3.0', '< 5.0']
|
||||
s.add_development_dependency 'sinatra', '~> 1.0'
|
||||
s.add_development_dependency 'rack-test', '>= 0.6'
|
||||
s.add_development_dependency 'rspec-rails', '~> 2.99'
|
||||
s.add_development_dependency 'rspec-rails', '~> 3.1.0'
|
||||
s.add_development_dependency 'generator_spec'
|
||||
s.add_development_dependency 'database_cleaner', '~> 1.2'
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
require 'generator_spec/test_case'
|
||||
require File.expand_path('../../../lib/generators/paper_trail/install_generator', __FILE__)
|
||||
|
||||
|
@ -15,7 +15,7 @@ describe PaperTrail::InstallGenerator, :type => :generator do
|
|||
end
|
||||
|
||||
it "generates a migration for creating the 'versions' table" do
|
||||
destination_root.should have_structure {
|
||||
expect(destination_root).to have_structure {
|
||||
directory 'db' do
|
||||
directory 'migrate' do
|
||||
migration 'create_versions' do
|
||||
|
@ -36,7 +36,7 @@ describe PaperTrail::InstallGenerator, :type => :generator do
|
|||
end
|
||||
|
||||
it "generates a migration for creating the 'versions' table" do
|
||||
destination_root.should have_structure {
|
||||
expect(destination_root).to have_structure {
|
||||
directory 'db' do
|
||||
directory 'migrate' do
|
||||
migration 'create_versions' do
|
||||
|
@ -50,7 +50,7 @@ describe PaperTrail::InstallGenerator, :type => :generator do
|
|||
end
|
||||
|
||||
it "generates a migration for adding the 'object_changes' column to the 'versions' table" do
|
||||
destination_root.should have_structure {
|
||||
expect(destination_root).to have_structure {
|
||||
directory 'db' do
|
||||
directory 'migrate' do
|
||||
migration 'add_object_changes_to_versions' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
describe Gadget do
|
||||
describe Gadget, :type => :model do
|
||||
it { should be_versioned }
|
||||
|
||||
let(:gadget) { Gadget.create!(:name => 'Wrench', :brand => 'Acme') }
|
||||
|
@ -22,16 +22,16 @@ describe Gadget do
|
|||
describe "Methods" do
|
||||
describe "Instance", :versioning => true do
|
||||
describe "private" do
|
||||
describe :changed_notably? do
|
||||
describe '#changed_notably?' do
|
||||
subject { Gadget.new(:created_at => Time.now) }
|
||||
|
||||
# apparently the private methods list in Ruby18 is different than in Ruby19+
|
||||
if RUBY_VERSION.to_f >= 1.9
|
||||
its(:private_methods) { should include(:changed_notably?) }
|
||||
it { expect(subject.private_methods).to include(:changed_notably?) }
|
||||
end
|
||||
|
||||
context "create events" do
|
||||
it { subject.send(:changed_notably?).should == true }
|
||||
it { expect(subject.send(:changed_notably?)).to be true }
|
||||
end
|
||||
|
||||
context "update events" do
|
||||
|
@ -40,24 +40,24 @@ describe Gadget do
|
|||
context "without update timestamps" do
|
||||
it "should only acknowledge non-ignored attrs" do
|
||||
subject.name = 'Wrench'
|
||||
subject.send(:changed_notably?).should == true
|
||||
expect(subject.send(:changed_notably?)).to be true
|
||||
end
|
||||
|
||||
it "should not acknowledge ignored attrs and timestamps only" do
|
||||
subject.brand = 'Acme'
|
||||
subject.send(:changed_notably?).should == false
|
||||
expect(subject.send(:changed_notably?)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context "with update timestamps" do
|
||||
it "should only acknowledge non-ignored attrs" do
|
||||
subject.name, subject.updated_at = 'Wrench', Time.now
|
||||
subject.send(:changed_notably?).should == true
|
||||
expect(subject.send(:changed_notably?)).to be true
|
||||
end
|
||||
|
||||
it "should not acknowledge ignored attrs and timestamps only" do
|
||||
subject.brand, subject.updated_at = 'Acme', Time.now
|
||||
subject.send(:changed_notably?).should == false
|
||||
expect(subject.send(:changed_notably?)).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
describe JoinedVersion, :versioning => true do
|
||||
it { JoinedVersion.superclass.should == PaperTrail::Version }
|
||||
describe JoinedVersion, :type => :model, :versioning => true do
|
||||
it { expect(JoinedVersion.superclass).to be PaperTrail::Version }
|
||||
|
||||
let(:widget) { Widget.create!(:name => Faker::Name.name) }
|
||||
let(:version) { JoinedVersion.first }
|
||||
|
||||
describe "Scopes" do
|
||||
describe "default_scope" do
|
||||
it { JoinedVersion.default_scopes.should_not be_empty }
|
||||
it { expect(JoinedVersion.default_scopes).not_to be_empty }
|
||||
end
|
||||
|
||||
describe "VersionConcern::ClassMethods" do
|
||||
before { widget } # persist a widget
|
||||
|
||||
describe :subsequent do
|
||||
describe '#subsequent' do
|
||||
it "shouldn't error out when there is a default_scope that joins" do
|
||||
JoinedVersion.subsequent(version).first
|
||||
end
|
||||
end
|
||||
|
||||
describe :preceding do
|
||||
describe '#preceding' do
|
||||
it "shouldn't error out when there is a default scope that joins" do
|
||||
JoinedVersion.preceding(version).first
|
||||
end
|
||||
end
|
||||
|
||||
describe :between do
|
||||
describe '#between' do
|
||||
it "shouldn't error out when there is a default scope that joins" do
|
||||
JoinedVersion.between(Time.now, 1.minute.from_now).first
|
||||
end
|
||||
|
@ -35,8 +35,8 @@ describe JoinedVersion, :versioning => true do
|
|||
end
|
||||
|
||||
describe "Methods" do
|
||||
describe :index do
|
||||
it { should respond_to(:index) }
|
||||
describe '#index' do
|
||||
it { is_expected.to respond_to(:index) }
|
||||
|
||||
it "shouldn't error out when there is a default scope that joins" do
|
||||
widget # persist a widget
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
# This model is in the test suite soley for the purpose of testing ActiveRecord::Enum,
|
||||
# which is available in ActiveRecord4+ only
|
||||
describe PostWithStatus do
|
||||
describe PostWithStatus, :type => :model do
|
||||
if defined?(ActiveRecord::Enum)
|
||||
with_versioning do
|
||||
let(:post) { PostWithStatus.create!(:status => 'draft') }
|
||||
|
@ -10,7 +10,7 @@ describe PostWithStatus do
|
|||
it "should stash the enum value properly in versions" do
|
||||
post.published!
|
||||
post.archived!
|
||||
post.previous_version.published?.should == true
|
||||
expect(post.previous_version.published?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,49 +1,49 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
describe PaperTrail::Version do
|
||||
describe PaperTrail::Version, :type => :model do
|
||||
it "should include the `VersionConcern` module to get base functionality" do
|
||||
PaperTrail::Version.should include(PaperTrail::VersionConcern)
|
||||
expect(PaperTrail::Version).to include(PaperTrail::VersionConcern)
|
||||
end
|
||||
|
||||
describe "Attributes" do
|
||||
it { should have_db_column(:item_type).of_type(:string) }
|
||||
it { should have_db_column(:item_id).of_type(:integer) }
|
||||
it { should have_db_column(:event).of_type(:string) }
|
||||
it { should have_db_column(:whodunnit).of_type(:string) }
|
||||
it { should have_db_column(:object).of_type(:text) }
|
||||
it { should have_db_column(:created_at).of_type(:datetime) }
|
||||
it { is_expected.to have_db_column(:item_type).of_type(:string) }
|
||||
it { is_expected.to have_db_column(:item_id).of_type(:integer) }
|
||||
it { is_expected.to have_db_column(:event).of_type(:string) }
|
||||
it { is_expected.to have_db_column(:whodunnit).of_type(:string) }
|
||||
it { is_expected.to have_db_column(:object).of_type(:text) }
|
||||
it { is_expected.to have_db_column(:created_at).of_type(:datetime) }
|
||||
end
|
||||
|
||||
describe "Indexes" do
|
||||
it { should have_db_index([:item_type, :item_id]) }
|
||||
it { is_expected.to have_db_index([:item_type, :item_id]) }
|
||||
end
|
||||
|
||||
describe "Methods" do
|
||||
describe "Instance" do
|
||||
subject { PaperTrail::Version.new(attributes) rescue PaperTrail::Version.new }
|
||||
|
||||
describe :terminator do
|
||||
it { should respond_to(:terminator) }
|
||||
describe '#terminator' do
|
||||
it { is_expected.to respond_to(:terminator) }
|
||||
|
||||
let(:attributes) { {:whodunnit => Faker::Name.first_name} }
|
||||
|
||||
it "is an alias for the `whodunnit` attribute" do
|
||||
subject.whodunnit.should == attributes[:whodunnit]
|
||||
expect(subject.whodunnit).to eq(attributes[:whodunnit])
|
||||
end
|
||||
end
|
||||
|
||||
describe :version_author do
|
||||
it { should respond_to(:version_author) }
|
||||
describe '#version_author' do
|
||||
it { is_expected.to respond_to(:version_author) }
|
||||
|
||||
it "should be an alias for the `terminator` method" do
|
||||
subject.method(:version_author).should == subject.method(:terminator)
|
||||
expect(subject.method(:version_author)).to eq(subject.method(:terminator))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Class" do
|
||||
describe :where_object do
|
||||
it { PaperTrail::Version.should respond_to(:where_object) }
|
||||
describe '#where_object' do
|
||||
it { expect(PaperTrail::Version).to respond_to(:where_object) }
|
||||
|
||||
context "invalid arguments" do
|
||||
it "should raise an error" do
|
||||
|
@ -64,21 +64,21 @@ describe PaperTrail::Version do
|
|||
end
|
||||
|
||||
context "`serializer == YAML`" do
|
||||
specify { PaperTrail.serializer == PaperTrail::Serializers::YAML }
|
||||
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
|
||||
|
||||
it "should be able to locate versions according to their `object` contents" do
|
||||
PaperTrail::Version.where_object(:name => name).should == [widget.versions[1]]
|
||||
PaperTrail::Version.where_object(:an_integer => 100).should == [widget.versions[2]]
|
||||
expect(PaperTrail::Version.where_object(:name => name)).to eq([widget.versions[1]])
|
||||
expect(PaperTrail::Version.where_object(:an_integer => 100)).to eq([widget.versions[2]])
|
||||
end
|
||||
end
|
||||
|
||||
context "`serializer == JSON`" do
|
||||
before { PaperTrail.serializer = PaperTrail::Serializers::JSON }
|
||||
specify { PaperTrail.serializer == PaperTrail::Serializers::JSON }
|
||||
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON }
|
||||
|
||||
it "should be able to locate versions according to their `object` contents" do
|
||||
PaperTrail::Version.where_object(:name => name).should == [widget.versions[1]]
|
||||
PaperTrail::Version.where_object(:an_integer => 100).should == [widget.versions[2]]
|
||||
expect(PaperTrail::Version.where_object(:name => name)).to eq([widget.versions[1]])
|
||||
expect(PaperTrail::Version.where_object(:an_integer => 100)).to eq([widget.versions[2]])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
describe Widget do
|
||||
describe Widget, :type => :model do
|
||||
describe '`be_versioned` matcher' do
|
||||
it { should be_versioned }
|
||||
end
|
||||
|
@ -15,22 +15,22 @@ describe Widget do
|
|||
end
|
||||
|
||||
it "is possible to do assertions on versions" do
|
||||
widget.should have_a_version_with :name => 'Leonard', :an_integer => 1
|
||||
widget.should have_a_version_with :an_integer => 1
|
||||
widget.should have_a_version_with :name => 'Tom'
|
||||
expect(widget).to have_a_version_with :name => 'Leonard', :an_integer => 1
|
||||
expect(widget).to have_a_version_with :an_integer => 1
|
||||
expect(widget).to have_a_version_with :name => 'Tom'
|
||||
end
|
||||
end
|
||||
|
||||
describe "`versioning` option" do
|
||||
context :enabled, :versioning => true do
|
||||
it 'should enable versioning for models wrapped within a block' do
|
||||
widget.versions.size.should == 1
|
||||
expect(widget.versions.size).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context '`disabled` (default)' do
|
||||
it 'should not enable versioning for models wrapped within a block not marked to used versioning' do
|
||||
widget.versions.size.should == 0
|
||||
expect(widget.versions.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -52,7 +52,7 @@ describe Widget do
|
|||
let(:widget) { Widget.create!(:name => 'Foobar', :created_at => Time.now - 1.week) }
|
||||
|
||||
it "corresponding version should use the widget's `created_at`" do
|
||||
widget.versions.last.created_at.to_i.should == widget.created_at.to_i
|
||||
expect(widget.versions.last.created_at.to_i).to eq(widget.created_at.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -61,15 +61,15 @@ describe Widget do
|
|||
|
||||
subject { widget.versions.last.reify }
|
||||
|
||||
it { subject.should_not be_live }
|
||||
it { expect(subject).not_to be_live }
|
||||
|
||||
it "should clear the `versions_association_name` virtual attribute" do
|
||||
subject.save!
|
||||
subject.should be_live
|
||||
expect(subject).to be_live
|
||||
end
|
||||
|
||||
it "corresponding version should use the widget updated_at" do
|
||||
widget.versions.last.created_at.to_i.should == widget.updated_at.to_i
|
||||
expect(widget.versions.last.created_at.to_i).to eq(widget.updated_at.to_i)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -79,10 +79,10 @@ describe Widget do
|
|||
end
|
||||
|
||||
it "should assign the version into the `versions_association_name`" do
|
||||
widget.version.should be_nil
|
||||
expect(widget.version).to be_nil
|
||||
widget.destroy
|
||||
widget.version.should_not be_nil
|
||||
widget.version.should == widget.versions.last
|
||||
expect(widget.version).not_to be_nil
|
||||
expect(widget.version).to eq(widget.versions.last)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -90,16 +90,16 @@ describe Widget do
|
|||
describe "Association", :versioning => true do
|
||||
describe "sort order" do
|
||||
it "should sort by the timestamp order from the `VersionConcern`" do
|
||||
widget.versions.to_sql.should ==
|
||||
widget.versions.reorder(PaperTrail::Version.timestamp_sort_order).to_sql
|
||||
expect(widget.versions.to_sql).to eq(
|
||||
widget.versions.reorder(PaperTrail::Version.timestamp_sort_order).to_sql)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Methods" do
|
||||
describe "Instance", :versioning => true do
|
||||
describe :originator do
|
||||
it { should respond_to(:originator) }
|
||||
describe '#originator' do
|
||||
it { is_expected.to respond_to(:originator) }
|
||||
|
||||
describe "return value" do
|
||||
let(:orig_name) { Faker::Name.name }
|
||||
|
@ -107,12 +107,12 @@ describe Widget do
|
|||
before { PaperTrail.whodunnit = orig_name }
|
||||
|
||||
context "accessed from live model instance" do
|
||||
specify { widget.should be_live }
|
||||
specify { expect(widget).to be_live }
|
||||
|
||||
it "should return the originator for the model at a given state" do
|
||||
widget.originator.should == orig_name
|
||||
expect(widget.originator).to eq(orig_name)
|
||||
widget.whodunnit(new_name) { |w| w.update_attributes(:name => 'Elizabeth') }
|
||||
widget.originator.should == new_name
|
||||
expect(widget.originator).to eq(new_name)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -127,11 +127,11 @@ describe Widget do
|
|||
let(:reified_widget) { widget.versions[1].reify }
|
||||
|
||||
it "should return the appropriate originator" do
|
||||
reified_widget.originator.should == orig_name
|
||||
expect(reified_widget.originator).to eq(orig_name)
|
||||
end
|
||||
|
||||
it "should not create a new model instance" do
|
||||
reified_widget.should_not be_new_record
|
||||
expect(reified_widget).not_to be_new_record
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -139,19 +139,19 @@ describe Widget do
|
|||
let(:reified_widget) { widget.versions[1].reify(:dup => true) }
|
||||
|
||||
it "should return the appropriate originator" do
|
||||
reified_widget.originator.should == orig_name
|
||||
expect(reified_widget.originator).to eq(orig_name)
|
||||
end
|
||||
|
||||
it "should not create a new model instance" do
|
||||
reified_widget.should be_new_record
|
||||
expect(reified_widget).to be_new_record
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe :version_at do
|
||||
it { should respond_to(:version_at) }
|
||||
describe '#version_at' do
|
||||
it { is_expected.to respond_to(:version_at) }
|
||||
|
||||
context "Timestamp argument is AFTER object has been destroyed" do
|
||||
before do
|
||||
|
@ -160,13 +160,13 @@ describe Widget do
|
|||
end
|
||||
|
||||
it "should return `nil`" do
|
||||
widget.version_at(Time.now).should be_nil
|
||||
expect(widget.version_at(Time.now)).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe :whodunnit do
|
||||
it { should respond_to(:whodunnit) }
|
||||
describe '#whodunnit' do
|
||||
it { is_expected.to respond_to(:whodunnit) }
|
||||
|
||||
context "no block given" do
|
||||
it "should raise an error" do
|
||||
|
@ -180,44 +180,44 @@ describe Widget do
|
|||
|
||||
before do
|
||||
PaperTrail.whodunnit = orig_name
|
||||
widget.versions.last.whodunnit.should == orig_name # persist `widget`
|
||||
expect(widget.versions.last.whodunnit).to eq(orig_name) # persist `widget`
|
||||
end
|
||||
|
||||
it "should modify value of `PaperTrail.whodunnit` while executing the block" do
|
||||
widget.whodunnit(new_name) do
|
||||
PaperTrail.whodunnit.should == new_name
|
||||
expect(PaperTrail.whodunnit).to eq(new_name)
|
||||
widget.update_attributes(:name => 'Elizabeth')
|
||||
end
|
||||
widget.versions.last.whodunnit.should == new_name
|
||||
expect(widget.versions.last.whodunnit).to eq(new_name)
|
||||
end
|
||||
|
||||
it "should revert the value of `PaperTrail.whodunnit` to it's previous value after executing the block" do
|
||||
widget.whodunnit(new_name) { |w| w.update_attributes(:name => 'Elizabeth') }
|
||||
PaperTrail.whodunnit.should == orig_name
|
||||
expect(PaperTrail.whodunnit).to eq(orig_name)
|
||||
end
|
||||
|
||||
context "error within block" do
|
||||
it "should ensure that the whodunnit value still reverts to it's previous value" do
|
||||
expect { widget.whodunnit(new_name) { raise } }.to raise_error
|
||||
PaperTrail.whodunnit.should == orig_name
|
||||
expect(PaperTrail.whodunnit).to eq(orig_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe :touch_with_version do
|
||||
it { should respond_to(:touch_with_version) }
|
||||
describe '#touch_with_version' do
|
||||
it { is_expected.to respond_to(:touch_with_version) }
|
||||
|
||||
it "should generate a version" do
|
||||
count = widget.versions.size
|
||||
widget.touch_with_version
|
||||
widget.versions.size.should == count + 1
|
||||
expect(widget.versions.size).to eq(count + 1)
|
||||
end
|
||||
|
||||
it "should increment the `:updated_at` timestamp" do
|
||||
time_was = widget.updated_at
|
||||
widget.touch_with_version
|
||||
widget.updated_at.should > time_was
|
||||
expect(widget.updated_at).to be > time_was
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -225,56 +225,56 @@ describe Widget do
|
|||
describe "Class" do
|
||||
subject { Widget }
|
||||
|
||||
describe :paper_trail_off! do
|
||||
it { should respond_to(:paper_trail_off!) }
|
||||
describe '#paper_trail_off!' do
|
||||
it { is_expected.to respond_to(:paper_trail_off!) }
|
||||
|
||||
it 'should set the `paper_trail_enabled_for_model?` to `false`' do
|
||||
subject.paper_trail_enabled_for_model?.should == true
|
||||
expect(subject.paper_trail_enabled_for_model?).to be true
|
||||
subject.paper_trail_off!
|
||||
subject.paper_trail_enabled_for_model?.should == false
|
||||
expect(subject.paper_trail_enabled_for_model?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
describe :paper_trail_off do
|
||||
it { should respond_to(:paper_trail_off) }
|
||||
describe '#paper_trail_off' do
|
||||
it { is_expected.to respond_to(:paper_trail_off) }
|
||||
|
||||
it 'should set the invoke `paper_trail_off!`' do
|
||||
subject.should_receive(:warn)
|
||||
subject.should_receive(:paper_trail_off!)
|
||||
is_expected.to receive(:warn)
|
||||
is_expected.to receive(:paper_trail_off!)
|
||||
subject.paper_trail_off
|
||||
end
|
||||
|
||||
it 'should display a deprecation warning' do
|
||||
subject.should_receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 3.1")
|
||||
is_expected.to receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 3.1")
|
||||
subject.paper_trail_on
|
||||
end
|
||||
end
|
||||
|
||||
describe :paper_trail_on! do
|
||||
describe '#paper_trail_on!' do
|
||||
before { subject.paper_trail_off! }
|
||||
|
||||
it { should respond_to(:paper_trail_on!) }
|
||||
it { is_expected.to respond_to(:paper_trail_on!) }
|
||||
|
||||
it 'should set the `paper_trail_enabled_for_model?` to `true`' do
|
||||
subject.paper_trail_enabled_for_model?.should == false
|
||||
expect(subject.paper_trail_enabled_for_model?).to be false
|
||||
subject.paper_trail_on!
|
||||
subject.paper_trail_enabled_for_model?.should == true
|
||||
expect(subject.paper_trail_enabled_for_model?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
describe :paper_trail_on do
|
||||
describe '#paper_trail_on' do
|
||||
before { subject.paper_trail_off! }
|
||||
|
||||
it { should respond_to(:paper_trail_on) }
|
||||
it { is_expected.to respond_to(:paper_trail_on) }
|
||||
|
||||
it 'should set the invoke `paper_trail_on!`' do
|
||||
subject.should_receive(:warn)
|
||||
subject.should_receive(:paper_trail_on!)
|
||||
is_expected.to receive(:warn)
|
||||
is_expected.to receive(:paper_trail_on!)
|
||||
subject.paper_trail_on
|
||||
end
|
||||
|
||||
it 'should display a deprecation warning' do
|
||||
subject.should_receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 3.1")
|
||||
is_expected.to receive(:warn).with("DEPRECATED: use `paper_trail_on!` instead of `paper_trail_on`. Support for `paper_trail_on` will be removed in PaperTrail 3.1")
|
||||
subject.paper_trail_on
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
describe PaperTrail::VersionConcern do
|
||||
|
||||
before(:all) { require 'support/alt_db_init' }
|
||||
|
||||
it 'allows included class to have different connections' do
|
||||
Foo::Version.connection.should_not == Bar::Version.connection
|
||||
expect(Foo::Version.connection).not_to eq(Bar::Version.connection)
|
||||
end
|
||||
|
||||
it 'allows custom version class to share connection with superclass' do
|
||||
Foo::Version.connection.should == Foo::Document.connection
|
||||
Bar::Version.connection.should == Bar::Document.connection
|
||||
expect(Foo::Version.connection).to eq(Foo::Document.connection)
|
||||
expect(Bar::Version.connection).to eq(Bar::Document.connection)
|
||||
end
|
||||
|
||||
it 'can be used with class_name option' do
|
||||
Foo::Document.version_class_name.should == 'Foo::Version'
|
||||
Bar::Document.version_class_name.should == 'Bar::Version'
|
||||
expect(Foo::Document.version_class_name).to eq('Foo::Version')
|
||||
expect(Bar::Document.version_class_name).to eq('Bar::Version')
|
||||
end
|
||||
|
||||
describe 'persistence', :versioning => true do
|
||||
|
@ -25,8 +25,8 @@ describe PaperTrail::VersionConcern do
|
|||
end
|
||||
|
||||
it 'should store versions in the correct corresponding db location' do
|
||||
@foo_doc.versions.first.should be_instance_of(Foo::Version)
|
||||
@bar_doc.versions.first.should be_instance_of(Bar::Version)
|
||||
expect(@foo_doc.versions.first).to be_instance_of(Foo::Version)
|
||||
expect(@bar_doc.versions.first).to be_instance_of(Bar::Version)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'PaperTrail::VERSION' do
|
||||
describe PaperTrail::VERSION do
|
||||
|
||||
describe "Constants" do
|
||||
subject { PaperTrail::VERSION }
|
||||
|
||||
describe :MAJOR do
|
||||
it { should be_const_defined(:MAJOR) }
|
||||
it { subject::MAJOR.should be_a(Integer) }
|
||||
it { is_expected.to be_const_defined(:MAJOR) }
|
||||
it { expect(subject::MAJOR).to be_a(Integer) }
|
||||
end
|
||||
describe :MINOR do
|
||||
it { should be_const_defined(:MINOR) }
|
||||
it { subject::MINOR.should be_a(Integer) }
|
||||
it { is_expected.to be_const_defined(:MINOR) }
|
||||
it { expect(subject::MINOR).to be_a(Integer) }
|
||||
end
|
||||
describe :TINY do
|
||||
it { should be_const_defined(:TINY) }
|
||||
it { subject::TINY.should be_a(Integer) }
|
||||
it { is_expected.to be_const_defined(:TINY) }
|
||||
it { expect(subject::TINY).to be_a(Integer) }
|
||||
end
|
||||
describe :PRE do
|
||||
it { should be_const_defined(:PRE) }
|
||||
it { is_expected.to be_const_defined(:PRE) }
|
||||
if PaperTrail::VERSION::PRE
|
||||
it { subject::PRE.should be_instance_of(String) }
|
||||
it { expect(subject::PRE).to be_instance_of(String) }
|
||||
end
|
||||
end
|
||||
describe :STRING do
|
||||
it { should be_const_defined(:STRING) }
|
||||
it { subject::STRING.should be_instance_of(String) }
|
||||
it { is_expected.to be_const_defined(:STRING) }
|
||||
it { expect(subject::STRING).to be_instance_of(String) }
|
||||
|
||||
it "should join the numbers into a period separated string" do
|
||||
subject::STRING.should ==
|
||||
[subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join('.')
|
||||
expect(subject::STRING).to eq(
|
||||
[subject::MAJOR, subject::MINOR, subject::TINY, subject::PRE].compact.join('.'))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -37,8 +37,8 @@ describe 'PaperTrail::VERSION' do
|
|||
end
|
||||
|
||||
describe PaperTrail do
|
||||
describe :version do
|
||||
it { should respond_to(:version) }
|
||||
its(:version) { should == PaperTrail::VERSION::STRING }
|
||||
describe '#version' do
|
||||
it { is_expected.to respond_to(:version) }
|
||||
it { expect(subject.version).to eq(PaperTrail::VERSION::STRING) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,58 +1,58 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
describe "PaperTrail RSpec Helper" do
|
||||
context 'default' do
|
||||
it 'should have versioning off by default' do
|
||||
::PaperTrail.should_not be_enabled
|
||||
expect(PaperTrail).not_to be_enabled
|
||||
end
|
||||
it 'should turn versioning on in a `with_versioning` block' do
|
||||
::PaperTrail.should_not be_enabled
|
||||
expect(PaperTrail).not_to be_enabled
|
||||
with_versioning do
|
||||
::PaperTrail.should be_enabled
|
||||
expect(PaperTrail).to be_enabled
|
||||
end
|
||||
::PaperTrail.should_not be_enabled
|
||||
expect(PaperTrail).not_to be_enabled
|
||||
end
|
||||
|
||||
context "error within `with_versioning` block" do
|
||||
it "should revert the value of `PaperTrail.enabled?` to it's previous state" do
|
||||
::PaperTrail.should_not be_enabled
|
||||
expect(PaperTrail).not_to be_enabled
|
||||
expect { with_versioning { raise } }.to raise_error
|
||||
::PaperTrail.should_not be_enabled
|
||||
expect(PaperTrail).not_to be_enabled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '`versioning: true`', :versioning => true do
|
||||
it 'should have versioning on by default' do
|
||||
::PaperTrail.should be_enabled
|
||||
expect(PaperTrail).to be_enabled
|
||||
end
|
||||
it 'should keep versioning on after a with_versioning block' do
|
||||
::PaperTrail.should be_enabled
|
||||
expect(PaperTrail).to be_enabled
|
||||
with_versioning do
|
||||
::PaperTrail.should be_enabled
|
||||
expect(PaperTrail).to be_enabled
|
||||
end
|
||||
::PaperTrail.should be_enabled
|
||||
expect(PaperTrail).to be_enabled
|
||||
end
|
||||
end
|
||||
|
||||
context '`with_versioning` block at class level' do
|
||||
it { ::PaperTrail.should_not be_enabled }
|
||||
it { expect(PaperTrail).not_to be_enabled }
|
||||
|
||||
with_versioning do
|
||||
it 'should have versioning on by default' do
|
||||
::PaperTrail.should be_enabled
|
||||
expect(PaperTrail).to be_enabled
|
||||
end
|
||||
end
|
||||
it 'should not leak the `enabled?` state into successive tests' do
|
||||
::PaperTrail.should_not be_enabled
|
||||
expect(PaperTrail).not_to be_enabled
|
||||
end
|
||||
end
|
||||
|
||||
describe :whodunnit do
|
||||
before(:all) { ::PaperTrail.whodunnit = 'foobar' }
|
||||
before(:all) { PaperTrail.whodunnit = 'foobar' }
|
||||
|
||||
it "should get set to `nil` by default" do
|
||||
::PaperTrail.whodunnit.should be_nil
|
||||
expect(PaperTrail.whodunnit).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -60,7 +60,7 @@ describe "PaperTrail RSpec Helper" do
|
|||
before(:all) { ::PaperTrail.controller_info = {:foo => 'bar'} }
|
||||
|
||||
it "should get set to an empty hash before each test" do
|
||||
::PaperTrail.controller_info.should == {}
|
||||
expect(PaperTrail.controller_info).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
30
spec/rails_helper.rb
Normal file
30
spec/rails_helper.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
ENV["DB"] ||= 'sqlite'
|
||||
|
||||
unless File.exists?(File.expand_path('../../test/dummy/config/database.yml', __FILE__))
|
||||
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
|
||||
end
|
||||
|
||||
require 'spec_helper'
|
||||
require File.expand_path('../../test/dummy/config/environment', __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'shoulda/matchers'
|
||||
require 'ffaker'
|
||||
|
||||
# Checks for pending migrations before tests are run.
|
||||
# If you are not using ActiveRecord, you can remove this line.
|
||||
# ActiveRecord::Migration.maintain_test_schema!
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
# The different available types are documented in the features, such as in
|
||||
# https://relishapp.com/rspec/rspec-rails/docs
|
||||
# config.infer_spec_type_from_file_location!
|
||||
end
|
|
@ -1,19 +1,19 @@
|
|||
require 'spec_helper'
|
||||
require 'rails_helper'
|
||||
|
||||
describe "Articles" do
|
||||
describe "Articles management", :type => :request, :order => :defined do
|
||||
let(:valid_params) { { :article => { :title => 'Doh', :content => Faker::Lorem.sentence } } }
|
||||
|
||||
context "versioning disabled" do
|
||||
specify { PaperTrail.should_not be_enabled }
|
||||
specify { expect(PaperTrail).not_to be_enabled }
|
||||
|
||||
it "should not create a version" do
|
||||
PaperTrail.should be_enabled_for_controller
|
||||
expect { post articles_path(valid_params) }.to_not change(PaperTrail::Version, :count)
|
||||
PaperTrail.should_not be_enabled_for_controller
|
||||
expect(PaperTrail).to be_enabled_for_controller
|
||||
expect { post(articles_path, valid_params) }.to_not change(PaperTrail::Version, :count)
|
||||
expect(PaperTrail).not_to be_enabled_for_controller
|
||||
end
|
||||
|
||||
it "should not leak the state of the `PaperTrail.enabled_for_controller?` into the next test" do
|
||||
PaperTrail.should be_enabled_for_controller
|
||||
expect(PaperTrail).to be_enabled_for_controller
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,10 +23,10 @@ describe "Articles" do
|
|||
context "`current_user` method returns a `String`" do
|
||||
if RUBY_VERSION.to_f >= 1.9
|
||||
it "should set that value as the `whodunnit`" do
|
||||
expect { post articles_path(valid_params) }.to change(PaperTrail::Version, :count).by(1)
|
||||
article.title.should == 'Doh'
|
||||
PaperTrail.whodunnit.should == 'foobar'
|
||||
article.versions.last.whodunnit.should == 'foobar'
|
||||
expect { post articles_path, valid_params }.to change(PaperTrail::Version, :count).by(1)
|
||||
expect(article.title).to eq('Doh')
|
||||
expect(PaperTrail.whodunnit).to eq('foobar')
|
||||
expect(article.versions.last.whodunnit).to eq('foobar')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,48 +1,89 @@
|
|||
ENV["RAILS_ENV"] ||= 'test'
|
||||
ENV["DB"] ||= 'sqlite'
|
||||
|
||||
unless File.exists?(File.expand_path('../../test/dummy/config/database.yml', __FILE__))
|
||||
warn "WARNING: No database.yml detected for the dummy app, please run `rake prepare` first"
|
||||
end
|
||||
|
||||
require File.expand_path('../../test/dummy/config/environment', __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'rspec/autorun'
|
||||
require 'shoulda/matchers'
|
||||
require 'ffaker'
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each { |f| require f }
|
||||
|
||||
# This file was generated by the `rspec --init` command. Conventionally, all
|
||||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
||||
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
||||
# file to always be loaded, without a need to explicitly require it in any files.
|
||||
#
|
||||
# Given that it is always loaded, you are encouraged to keep this file as
|
||||
# light-weight as possible. Requiring heavyweight dependencies from this file
|
||||
# will add to the boot time of your test suite on EVERY test run, even for an
|
||||
# individual file that may not need all of that loaded. Instead, consider making
|
||||
# a separate helper file that requires the additional dependencies and performs
|
||||
# the additional setup, and require it from the spec files that actually need it.
|
||||
#
|
||||
# The `.rspec` file also contains a few flags that are not defaults but that
|
||||
# users commonly want.
|
||||
#
|
||||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
||||
RSpec.configure do |config|
|
||||
config.treat_symbols_as_metadata_keys_with_true_values = true
|
||||
# rspec-expectations config goes here. You can use an alternate
|
||||
# assertion/expectation library such as wrong or the stdlib/minitest
|
||||
# assertions if you prefer.
|
||||
config.expect_with :rspec do |expectations|
|
||||
# This option will default to `true` in RSpec 4. It makes the `description`
|
||||
# and `failure_message` of custom matchers include text for helper methods
|
||||
# defined using `chain`, e.g.:
|
||||
# be_bigger_than(2).and_smaller_than(4).description
|
||||
# # => "be bigger than 2 and smaller than 4"
|
||||
# ...rather than:
|
||||
# # => "be bigger than 2"
|
||||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
||||
end
|
||||
|
||||
# ## Mock Framework
|
||||
#
|
||||
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
||||
#
|
||||
# config.mock_with :mocha
|
||||
# config.mock_with :flexmock
|
||||
# config.mock_with :rr
|
||||
# rspec-mocks config goes here. You can use an alternate test double
|
||||
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
||||
config.mock_with :rspec do |mocks|
|
||||
# Prevents you from mocking or stubbing a method that does not exist on
|
||||
# a real object. This is generally recommended, and will default to
|
||||
# `true` in RSpec 4.
|
||||
mocks.verify_partial_doubles = true
|
||||
end
|
||||
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
# The settings below are suggested to provide a good initial experience
|
||||
# with RSpec, but feel free to customize to your heart's content.
|
||||
=begin
|
||||
# These two settings work together to allow you to limit a spec run
|
||||
# to individual examples or groups you care about by tagging them with
|
||||
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
||||
# get run.
|
||||
config.filter_run :focus
|
||||
config.run_all_when_everything_filtered = true
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
||||
# For more details, see:
|
||||
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
||||
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
||||
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
||||
config.disable_monkey_patching!
|
||||
|
||||
# If true, the base class of anonymous controllers will be inferred
|
||||
# automatically. This will be the default behavior in future versions of
|
||||
# rspec-rails.
|
||||
config.infer_base_class_for_anonymous_controllers = false
|
||||
# This setting enables warnings. It's recommended, but in some cases may
|
||||
# be too noisy due to issues in dependencies.
|
||||
config.warnings = true
|
||||
|
||||
# Many RSpec users commonly either run the entire suite or an individual
|
||||
# file, and it's useful to allow more verbose output when running an
|
||||
# individual spec file.
|
||||
if config.files_to_run.one?
|
||||
# Use the documentation formatter for detailed output,
|
||||
# unless a formatter has already been configured
|
||||
# (e.g. via a command-line flag).
|
||||
config.default_formatter = 'doc'
|
||||
end
|
||||
|
||||
# Print the 10 slowest examples and example groups at the
|
||||
# end of the spec run, to help surface which specs are running
|
||||
# particularly slow.
|
||||
config.profile_examples = 10
|
||||
|
||||
# Run specs in random order to surface order dependencies. If you find an
|
||||
# order dependency and want to debug it, you can fix the order by providing
|
||||
# the seed, which is printed after each run.
|
||||
# --seed 1234
|
||||
# config.order = 'random'
|
||||
config.order = :random
|
||||
|
||||
# Seed global randomization in this process using the `--seed` CLI option.
|
||||
# Setting this allows you to use `--seed` to deterministically reproduce
|
||||
# test failures related to randomization by passing the same `--seed` value
|
||||
# as the one that triggered the failure.
|
||||
Kernel.srand config.seed
|
||||
=end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue