2017-12-11 04:05:11 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-30 04:58:26 +00:00
|
|
|
require "spec_helper"
|
2013-11-16 23:39:08 +00:00
|
|
|
|
2017-05-21 05:41:20 +00:00
|
|
|
RSpec.describe "Articles management", type: :request, order: :defined do
|
2016-03-05 22:07:32 +00:00
|
|
|
let(:valid_params) { { article: { title: "Doh", content: FFaker::Lorem.sentence } } }
|
2013-11-16 23:39:08 +00:00
|
|
|
|
|
|
|
context "versioning disabled" do
|
2014-10-09 19:04:17 +00:00
|
|
|
specify { expect(PaperTrail).not_to be_enabled }
|
2013-11-16 23:39:08 +00:00
|
|
|
|
2017-04-01 05:50:13 +00:00
|
|
|
it "does not create a version" do
|
2018-02-01 17:04:50 +00:00
|
|
|
expect(PaperTrail.request).to be_enabled_for_controller
|
2016-02-15 23:27:57 +00:00
|
|
|
expect {
|
|
|
|
post articles_path, params_wrapper(valid_params)
|
2017-04-01 05:59:47 +00:00
|
|
|
}.not_to change(PaperTrail::Version, :count)
|
2013-11-16 23:39:08 +00:00
|
|
|
end
|
|
|
|
|
2018-02-01 17:04:50 +00:00
|
|
|
it "does not leak the state of the `PaperTrail.request.enabled_for_controller?` \
|
|
|
|
into the next test" do
|
|
|
|
expect(PaperTrail.request).to be_enabled_for_controller
|
2013-11-16 23:39:08 +00:00
|
|
|
end
|
|
|
|
end
|
2014-03-20 20:04:53 +00:00
|
|
|
|
|
|
|
with_versioning do
|
|
|
|
let(:article) { Article.last }
|
|
|
|
|
|
|
|
context "`current_user` method returns a `String`" do
|
2017-04-01 05:50:13 +00:00
|
|
|
it "sets that value as the `whodunnit`" do
|
2016-02-15 23:27:57 +00:00
|
|
|
expect {
|
|
|
|
post articles_path, params_wrapper(valid_params)
|
|
|
|
}.to change(PaperTrail::Version, :count).by(1)
|
2016-03-05 22:07:32 +00:00
|
|
|
expect(article.title).to eq("Doh")
|
|
|
|
expect(article.versions.last.whodunnit).to eq("foobar")
|
2014-03-20 20:04:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-11-16 23:39:08 +00:00
|
|
|
end
|