public
Clone URL: git://github.com/robbyrussell/rubyurl.git
Search Repo:
commit  20157bf6ac66a72928a455a935a6e8e56bf6110e
tree    4cee3eb37e5b0f85dd6a5ed6e435b9349bc7beda
parent  3965c375e8e395640e8a382096821f83355e4961
rubyurl / spec / controllers / links_controller_spec.rb
100644 73 lines (57 sloc) 1.959 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
67
68
69
70
71
72
73
require File.dirname(__FILE__) + '/../spec_helper'
 
describe LinksController, "index action" do
  controller_name :links
  
  it "should redirect to the home action" do
    get :index
    response.should redirect_to( :action => 'home' )
  end
end
 
describe LinksController, "home action" do
  controller_name :links
  
  before(:each) do
    @link = mock('link')
    Link.stub!(:new).and_return(@link)
    get :home
  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