nicely working delete tests

This commit is contained in:
2022-12-11 22:50:50 +02:00
parent 350ebb33ef
commit 60b270786c
6 changed files with 46 additions and 490 deletions

View File

@ -1,4 +1,5 @@
require 'rails_helper'
require "git"
module Merged
RSpec.describe Card, type: :model do
@ -33,7 +34,6 @@ module Merged
Card.find(20).destroy
Card.reload
expect{Card.find(20) }.to raise_error(ActiveHash::RecordNotFound)
git = Git.open(Engine.root)
end
end

View File

@ -21,5 +21,25 @@ module Merged
expect(section.index).to be index + 1 # because we have human index
end
end
it "deletes " do
id = index.id
index.delete
expect{Page.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "destroys " do
id = index.id
index.destroy
Section.reload
expect{Page.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "destroys sections" do
id = index.sections.first.id
index.destroy
Section.reload
expect{Page.find(id) }.to raise_error(ActiveHash::RecordNotFound)
end
end
end

View File

@ -44,5 +44,25 @@ module Merged
it "last has no next" do
expect(last.next_section).to be nil
end
it "deletes " do
last_id = last.id
last.delete
expect{Section.find(last_id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "destroys " do
last_id = last.id
last.destroy
Section.reload
expect{Section.find(last_id) }.to raise_error(ActiveHash::RecordNotFound)
end
it "destroys cards" do
card_id = last.cards.first.id
last.destroy
Section.reload
expect{Card.find(card_id) }.to raise_error(ActiveHash::RecordNotFound)
end
end
end

View File

@ -1,4 +1,5 @@
require 'capybara/rspec'
require "git"
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@ -40,7 +41,10 @@ RSpec.configure do |config|
end
config.before(:each) do |example|
# reset data so we can delete/edit/add at will. aka DatabaseCleaner
module Merged
git = Git.open(Engine.root)
git.checkout_file("HEAD" , "test/dummy/merged")
[Page, Section, Card].each { |m| m.reload(true) }
end
end