Skip to content

Instantly share code, notes, and snippets.

@FestivalBobcats
Created November 7, 2011 16:23
Show Gist options
  • Save FestivalBobcats/1345428 to your computer and use it in GitHub Desktop.
Save FestivalBobcats/1345428 to your computer and use it in GitHub Desktop.
require 'acceptance/admin/admin_spec'
feature 'Channel management', :js => true, :admin => true do
let!(:channel) { Fabricate(:channel) }
# TODO: make helper for doing something like
# on_page admin_channels_path do
# scenario...
# Basically a way to avoid doing before(:each) to visit a page before all scenarios in a context
context 'on the index page' do
background do
visit admin_channels_path
end
scenario 'all channels should be listed' do
find('#channels').should have_content(channel.name)
end
end
context 'on the edit page' do
let!(:store) { Fabricate(:store) }
background do
visit admin_channel_path(channel)
end
context 'when editing store_links' do
shared_examples 'a store_link li tag' do
subject { find("li##{ store.id }") }
context 'store select menu' do
subject { find('#store-select') }
it { should_not be_visible }
it { should_not have_content(store.handle) }
end
scenario 'should be linked in form' do
find('ul#store-links').should have_content(store.handle)
end
context 'when saving channel' do
def linked?
channel.reload.store_links.map(&:id).include?(store.id.to_s)
end
scenario 'store should be linked to channel' do
click_button('Update Channel')
sleep 0.05
linked?.should be_true
end
scenario 'toggled store_link should not be saved' do
subject.find('.unlink').click
click_button('Update Channel')
# TODO: weird hack
sleep 0.05
linked?.should be_false
end
end
end
describe 'existing link' do
# This will fire between calls to the visit admin_channel_path(channel) background
it_behaves_like 'a store_link li tag' do
background do
channel.store_links.create!(store_id: store.id)
# TODO: not dry
visit admin_channel_path(channel)
end
end
end
describe 'new link' do
# This background block must be embedded so it will fire after the admin_channel_path(channel) block
it_behaves_like 'a store_link li tag' do
background do
click_on('New store link')
select(store.handle, :from => 'store')
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment