Skip to content

Commit

Permalink
Merge pull request #749 from curationexperts/draftable-specs
Browse files Browse the repository at this point in the history
Clean up drafts in the test suite
  • Loading branch information
jenlindner committed Dec 12, 2017
2 parents ee35837 + 4babc74 commit 156a822
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions spec/controllers/hyrax/pdfs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
render_views
let(:work) { FactoryGirl.create(:pdf) }
let(:user) { FactoryGirl.create(:admin) }

before do
sign_in user
work.title = ["a_drafted_title"]
work.save_draft
end

after { work.delete_draft }

describe 'GET #edit' do
it 'applies a draft if one exists' do
get :edit, params: { id: work.id }
Expand All @@ -20,6 +24,7 @@
expect(response.body.match('a_drafted_title')).to be_nil
end
end

describe 'PATCH #update' do
it "deletes the draft when updating" do
post :update, params: { id: work.id, pdf: { title: 'new_title', description: 'test' } }
Expand Down
5 changes: 3 additions & 2 deletions spec/support/shared_examples/draftable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
raise 'Define `change_map` with `let(:change_map)` before using the ' \
'draftable model shared examples'
end

model.delete_draft

# The model has to be saved before drafts can be created
model.save
end
Expand Down Expand Up @@ -106,7 +109,6 @@
end

it 'overwrites changes for properties in the draft' do
optional "Sometimes fails on travis" if ENV['TRAVIS']
model.send("#{change_map.keys.last}=", ['I SHOULD BE DELETED'])
model.apply_draft
expect(model).to have_unordered_attributes(change_map)
Expand Down Expand Up @@ -143,7 +145,6 @@

describe '#draft_saved?' do
it 'does not exist before save' do
optional 'is optional on travis' if ENV['TRAVIS']
expect(model).not_to be_draft_saved
end
end
Expand Down

0 comments on commit 156a822

Please sign in to comment.