2014-10-09 15:04:17 -04:00
|
|
|
require 'rails_helper'
|
2013-11-16 18:39:08 -05:00
|
|
|
|
2014-10-09 15:04:17 -04:00
|
|
|
describe "Articles management", :type => :request, :order => :defined do
|
2013-11-16 18:39:08 -05:00
|
|
|
let(:valid_params) { { :article => { :title => 'Doh', :content => Faker::Lorem.sentence } } }
|
|
|
|
|
|
|
|
context "versioning disabled" do
|
2014-10-09 15:04:17 -04:00
|
|
|
specify { expect(PaperTrail).not_to be_enabled }
|
2013-11-16 18:39:08 -05:00
|
|
|
|
|
|
|
it "should not create a version" do
|
2014-10-09 15:04:17 -04:00
|
|
|
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
|
2013-11-16 18:39:08 -05:00
|
|
|
end
|
|
|
|
|
2014-03-03 16:52:14 -05:00
|
|
|
it "should not leak the state of the `PaperTrail.enabled_for_controller?` into the next test" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).to be_enabled_for_controller
|
2013-11-16 18:39:08 -05:00
|
|
|
end
|
|
|
|
end
|
2014-03-20 16:04:53 -04:00
|
|
|
|
|
|
|
with_versioning do
|
|
|
|
let(:article) { Article.last }
|
|
|
|
|
|
|
|
context "`current_user` method returns a `String`" do
|
2014-03-20 16:54:57 -04:00
|
|
|
if RUBY_VERSION.to_f >= 1.9
|
|
|
|
it "should set that value as the `whodunnit`" do
|
2014-10-09 15:04:17 -04:00
|
|
|
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')
|
2014-03-20 16:54:57 -04:00
|
|
|
end
|
2014-03-20 16:04:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-11-16 18:39:08 -05:00
|
|
|
end
|