Skip to content

Instantly share code, notes, and snippets.

@gerhard
Created October 16, 2008 11:30
Show Gist options
  • Save gerhard/17113 to your computer and use it in GitHub Desktop.
Save gerhard/17113 to your computer and use it in GitHub Desktop.
def get_site_id
(get_site && get_site.id) || '0'
end
def get_site_name
get_site.name
end
def get_site_code
params[:site_code]
end
def get_site_path
"/sites/" + get_site_code
end
def get_site
@current_site ||= Site.find_by_site_code(params[:site_code])
end
def site
@current_site ||= Site.find_by_site_code(params[:site_code])
end
def site_path
"/sites/" + params[:site_code]
end
describe '#site' do
it 'should return the site we have stored in @current_site' do
@current_site = Site.should_not_receive(:find_by_site_code)
@it.site.should eql(@current_site)
end
it 'should return the site based on the params[:site_code] if @current_site is not set' do
@it.site.should eql(nil)
@it.stub!(:params).and_return(:site_code => 'some_site')
Site.stub!(:find_by_site_code).with(params[:site_code]).and_return(@mysite)
@it.site.should eql(@mysite)
end
end
describe '#site_path' do
it 'should return the correct site_path' do
@it.stub!(:params).and_return(:site_code => 'some_site')
@it.site_path.should eql('/sites/some_site')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment