Sha256: 7e2c103764b7831b6710e81f1624589ad3e97a8f48b1f8e87fa57d4c56710677
Contents?: true
Size: 1.73 KB
Versions: 2
Compression:
Stored size: 1.73 KB
Contents
require 'spec_helper' class SlugHistoryRspecModel < RspecActiveModelBase simple_slug :name, history: true end describe 'slug history' do describe 'history records handling' do before do SlugHistoryRspecModel.any_instance.stub(:simple_slug_exists?).and_return(false) end it 'create' do relation = double ::SimpleSlug::HistorySlug.should_receive(:where).once.ordered.with(sluggable_type: 'SlugHistoryRspecModel', sluggable_id: 1, slug: 'hello').and_return(relation) relation.should_receive(:first_or_create) SlugHistoryRspecModel.create(id: 1, name: 'Hello') end it 'cleanup' do relation = double relation.stub(:first_or_create) ::SimpleSlug::HistorySlug.stub(:where).and_return(relation) relation.should_receive(:delete_all) SlugHistoryRspecModel.create(name: 'Hello', id: 1).destroy end end describe 'conflicts' do it 'history slug exists' do record = SlugGenerationRspecModel.new(name: 'Hi') record.stub(:simple_slug_base_exists?).and_return(false) record.should_receive(:simple_slug_history_exists?).once.ordered.and_return(true) record.should_receive(:simple_slug_history_exists?).once.ordered.and_return(false) record.save record.slug.should start_with('hi--') end end describe '#friendly_find' do before do SlugHistoryRspecModel.stub(:find_by) end it 'find from history' do record = double('history') record.stub(:sluggable_id).and_return(1) ::SimpleSlug::HistorySlug.should_receive(:find_by!).with(slug: 'title').and_return(record) SlugHistoryRspecModel.should_receive(:find).with(1).and_return(record) SlugHistoryRspecModel.friendly_find('title') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
simple_slug-0.1.0 | spec/simple_slug/history_spec.rb |
simple_slug-0.0.1 | spec/simple_slug/history_spec.rb |