paper-trail-gem--paper_trail/spec/requests/articles_spec.rb

38 lines
1.1 KiB
Ruby
Raw Normal View History

2017-12-11 04:05:11 +00:00
# frozen_string_literal: true
require "spec_helper"
RSpec.describe "Articles management", type: :request, order: :defined do
let(:valid_params) { { article: { title: "Doh", content: FFaker::Lorem.sentence } } }
context "versioning disabled" do
specify { expect(PaperTrail).not_to be_enabled }
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)
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
end
end
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)
expect(article.title).to eq("Doh")
expect(article.versions.last.whodunnit).to eq("foobar")
end
end
end
end