public
Description: Your favorite URL-shortening service in all of Ruby land
Homepage: http://rubyurl.com
Clone URL: git://github.com/robbyrussell/rubyurl.git
commit  f3b845519de3fbf74bd4885c69edfcf429dd6c53
tree    706aab7853c25f80dd2ade802abff6a27e82ac29
parent  66f94a5f2d8baba48e16ed14ee1275b79522a2ec
rubyurl / spec / controllers / links_controller_spec.rb
100644 66 lines (50 sloc) 1.765 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require File.dirname(__FILE__) + '/../spec_helper'
 
describe LinksController, "index action" do
  controller_name :links
  
  before(:each) do
    @link = mock('link')
    Link.stub!(:new).and_return(@link)
    get :index
  end
  
  it "should render the index view" do
    response.should render_template('links/index')
  end
 
  it "should instantiate a new link variable" do
    assigns[:link].should equal(@link)
  end
end
 
describe LinksController do
  include LinkSpecHelper
 
  controller_name :links
  
  it "should not save a new link wihout a website url" do
    post :create, :link => valid_attributes.except(:website_url)
    assigns(:link).should have_at_least(1).errors_on(:website_url)
  end
  
  it "should save a new link with valid attributes" do
    lambda do
      post :create, :link => valid_attributes
    end.should change(Link, :count).by(1)
  end
end
 
describe LinksController, "redirect routing" do
  controller_name :links
  
  it "should route to the redirect action in LinksController" do
    assert_routing '/abc', { :controller => 'links', :action => 'redirect', :token => 'abc' }
  end
  
  it "should redirect to the invalid page when the token is invalid" do
    get :redirect, :token => 'magoo'
    response.should redirect_to( :action => 'invalid' )
  end
end
 
describe LinksController, "redirect with token" do
  
  before(:each) do
    @link = mock( 'link' )
    Link.should_receive( :find_by_token ).with( 'abc' ).and_return( @link )
    @link.stub!( :add_visit )
    @link.should_receive( :website_url ).and_return( 'http://google.com/' )
    get :redirect, :token => 'abc'
  end
  
  it "should call redirected to a website when passed a token" do
    response.should redirect_to( 'http://google.com/' )
  end
end