Break long lines in `spec` dir

This commit is contained in:
Jared Beck 2016-02-15 18:27:57 -05:00
parent cf09e3b1c3
commit d86e6ec64c
6 changed files with 106 additions and 51 deletions

View File

@ -91,10 +91,6 @@ Metrics/ClassLength:
Metrics/CyclomaticComplexity:
Max: 13
Metrics/LineLength:
Exclude:
- spec/**/*
# Offense count: 18
# Configuration parameters: CountComments.
Metrics/MethodLength:

View File

@ -16,7 +16,9 @@ describe Gadget, :type => :model do
it "should still generate a version when only the `updated_at` attribute is updated" do
# Plus 1 second because MySQL lacks sub-second resolution
expect { gadget.update_attribute(:updated_at, Time.now + 1) }.to change{gadget.versions.size}.by(1)
expect {
gadget.update_attribute(:updated_at, Time.now + 1)
}.to change{gadget.versions.size}.by(1)
end
end

View File

@ -122,8 +122,12 @@ describe PaperTrail::Version, :type => :model do
if override
ActiveRecord::Base.connection.execute("SAVEPOINT pgtest;")
%w[object object_changes].each do |column|
ActiveRecord::Base.connection.execute("ALTER TABLE versions DROP COLUMN #{column};")
ActiveRecord::Base.connection.execute("ALTER TABLE versions ADD COLUMN #{column} #{override};")
ActiveRecord::Base.connection.execute(
"ALTER TABLE versions DROP COLUMN #{column};"
)
ActiveRecord::Base.connection.execute(
"ALTER TABLE versions ADD COLUMN #{column} #{override};"
)
end
PaperTrail::Version.reset_column_information
end
@ -140,8 +144,12 @@ describe PaperTrail::Version, :type => :model do
context "invalid arguments" do
it "should raise an error" do
expect { PaperTrail::Version.where_object(:foo) }.to raise_error(ArgumentError)
expect { PaperTrail::Version.where_object([]) }.to raise_error(ArgumentError)
expect {
PaperTrail::Version.where_object(:foo)
}.to raise_error(ArgumentError)
expect {
PaperTrail::Version.where_object([])
}.to raise_error(ArgumentError)
end
end
@ -157,24 +165,41 @@ describe PaperTrail::Version, :type => :model do
end
context "`serializer == YAML`" do
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
specify do
expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML
end
it "should be able to locate versions according to their `object` contents" do
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]])
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(:all) { 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
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]])
context "JSON serializer" do
before(:all) do
PaperTrail.serializer = PaperTrail::Serializers::JSON
end
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }
specify do
expect(PaperTrail.serializer).to be PaperTrail::Serializers::JSON
end
it "should be able to locate versions according to their `object` contents" do
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
after(:all) do
PaperTrail.serializer = PaperTrail::Serializers::YAML
end
end
end
end
@ -182,8 +207,12 @@ describe PaperTrail::Version, :type => :model do
describe '#where_object_changes' do
context "invalid arguments" do
it "should raise an error" do
expect { PaperTrail::Version.where_object_changes(:foo) }.to raise_error(ArgumentError)
expect { PaperTrail::Version.where_object_changes([]) }.to raise_error(ArgumentError)
expect {
PaperTrail::Version.where_object_changes(:foo)
}.to raise_error(ArgumentError)
expect {
PaperTrail::Version.where_object_changes([])
}.to raise_error(ArgumentError)
end
end
@ -198,32 +227,48 @@ describe PaperTrail::Version, :type => :model do
widget.update_attributes!(:name => FFaker::Name.last_name, :an_integer => int)
end
context "`serializer == YAML`" do
context "YAML serializer" do
specify { expect(PaperTrail.serializer).to be PaperTrail::Serializers::YAML }
it "should be able to locate versions according to their `object_changes` contents" do
expect(widget.versions.where_object_changes(:name => name)).to eq(widget.versions[0..1])
expect(widget.versions.where_object_changes(:an_integer => 77)).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => int)).to eq([widget.versions.last])
it "locates versions according to their `object_changes` contents" do
expect(
widget.versions.where_object_changes(:name => name)
).to eq(widget.versions[0..1])
expect(
widget.versions.where_object_changes(:an_integer => 77)
).to eq(widget.versions[1..2])
expect(
widget.versions.where_object_changes(:an_integer => int)
).to eq([widget.versions.last])
end
it "should be able to handle queries for multiple attributes" do
expect(widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')).to eq(widget.versions[1..2])
it "handles queries for multiple attributes" do
expect(
widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')
).to eq(widget.versions[1..2])
end
end
context "`serializer == JSON`" do
context "JSON serializer" do
before(:all) { 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_changes` contents" do
expect(widget.versions.where_object_changes(:name => name)).to eq(widget.versions[0..1])
expect(widget.versions.where_object_changes(:an_integer => 77)).to eq(widget.versions[1..2])
expect(widget.versions.where_object_changes(:an_integer => int)).to eq([widget.versions.last])
it "locates versions according to their `object_changes` contents" do
expect(
widget.versions.where_object_changes(:name => name)
).to eq(widget.versions[0..1])
expect(
widget.versions.where_object_changes(:an_integer => 77)
).to eq(widget.versions[1..2])
expect(
widget.versions.where_object_changes(:an_integer => int)
).to eq([widget.versions.last])
end
it "should be able to handle queries for multiple attributes" do
expect(widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')).to eq(widget.versions[1..2])
it "handles queries for multiple attributes" do
expect(
widget.versions.where_object_changes(:an_integer => 77, :name => 'foobar')
).to eq(widget.versions[1..2])
end
after(:all) { PaperTrail.serializer = PaperTrail::Serializers::YAML }

View File

@ -21,15 +21,15 @@ describe Widget, :type => :model do
end
end
describe "`versioning` option" do
context :enabled, :versioning => true do
it 'should enable versioning for models wrapped within a block' do
describe "versioning option" do
context "enabled", :versioning => true do
it "should enable versioning" do
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
context "disabled (default)" do
it "should not enable versioning" do
expect(widget.versions.size).to eq(0)
end
end
@ -42,7 +42,7 @@ describe Widget, :type => :model do
subject { widget.versions.last.reify }
it "should reset the value for the timestamp attrs for update so that value gets updated properly" do
it "resets value for timestamp attrs for update so that value gets updated properly" do
# Travel 1 second because MySQL lacks sub-second resolution
Timecop.travel(1) do
expect { subject.save! }.to change(subject, :updated_at)
@ -214,7 +214,9 @@ describe Widget, :type => :model do
context "no block given" do
it "should raise an error" do
expect { widget.whodunnit('Ben') }.to raise_error(ArgumentError, 'expected to receive a block')
expect {
widget.whodunnit('Ben')
}.to raise_error(ArgumentError, 'expected to receive a block')
end
end
@ -235,13 +237,15 @@ describe Widget, :type => :model do
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') }
expect(PaperTrail.whodunnit).to eq(orig_name)
context "after executing the block" do
it "reverts value of whodunnit to previous value" do
widget.whodunnit(new_name) { |w| w.update_attributes(:name => 'Elizabeth') }
expect(PaperTrail.whodunnit).to eq(orig_name)
end
end
context "error within block" do
it "should ensure that the whodunnit value still reverts to it's previous value" do
it "still reverts the whodunnit value to previous value" do
expect {
widget.whodunnit(new_name) { raise }
}.to raise_error(RuntimeError)

View File

@ -8,7 +8,9 @@ describe "Articles management", :type => :request, :order => :defined do
it "should not create a version" do
expect(PaperTrail).to be_enabled_for_controller
expect { post articles_path, params_wrapper(valid_params) }.to_not change(PaperTrail::Version, :count)
expect {
post articles_path, params_wrapper(valid_params)
}.to_not change(PaperTrail::Version, :count)
end
it "should not leak the state of the `PaperTrail.enabled_for_controller?` into the next test" do
@ -21,7 +23,9 @@ describe "Articles management", :type => :request, :order => :defined do
context "`current_user` method returns a `String`" do
it "should set that value as the `whodunnit`" do
expect { post articles_path, params_wrapper(valid_params) }.to change(PaperTrail::Version, :count).by(1)
expect {
post articles_path, params_wrapper(valid_params)
}.to change(PaperTrail::Version, :count).by(1)
expect(article.title).to eq('Doh')
expect(article.versions.last.whodunnit).to eq('foobar')
end

View File

@ -103,13 +103,17 @@ RSpec.configure do |config|
=end
end
def active_record_gem_version
Gem::Version.new(ActiveRecord::VERSION::STRING)
end
# Wrap args in a hash to support the ActionController::TestCase and
# ActionDispatch::Integration HTTP request method switch to keyword args
# (see https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md)
def params_wrapper(args)
if defined?(::Rails) && Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new('5.0.0.beta1')
if defined?(::Rails) && active_record_gem_version >= Gem::Version.new('5.0.0.beta1')
{ params: args }
else
args
end
end
end