Commit 9f3e6996

mo k <mo@mokhan.ca>
2011-06-22 03:43:50
fix profiles controller specs.
1 parent 49cfbc7
Changed files (3)
config/routes.rb
@@ -4,12 +4,15 @@ Cake::Application.routes.draw do
   resources :creations
   resources :authentications
   get "home/index"
+  get "profiles/index"
+  get "profiles/show"
 
   devise_for :users, :controllers => {:registrations => 'registrations'}
   match '/auth/:provider/callback' => 'authentications#create'
   match 'my_creations' => 'creations#mine', :as => 'my_creations', :method => 'GET'
   match 'artists' => 'profiles#index', :as => 'all_profiles', :method => 'GET'
   match 'artists/:id' => 'profiles#show', :as => 'profile', :method => 'GET'
+  match 'profiles/show/:id' => 'profiles#show', :as => 'profile', :method => 'GET'
 
   # authenticate :user do
   #   root :to => "home#index"
spec/controllers/profiles_controller_spec.rb
@@ -1,9 +1,19 @@
 require 'spec_helper'
 
 describe ProfilesController do
+  include Devise::TestHelpers
+
+  def mock_user(stubs={})
+    @mock_user ||= mock_model(User, stubs).as_null_object
+  end
+
+  before (:each) do
+    request.env['warden'] = mock(Warden, :authenticate => mock_user, :authenticate! => mock_user)
+  end
 
   describe "GET 'index'" do
     it "should be successful" do
+      User.stub(:all){ mock_user }
       get 'index'
       response.should be_success
     end
@@ -11,7 +21,8 @@ describe ProfilesController do
 
   describe "GET 'show'" do
     it "should be successful" do
-      get 'show'
+      User.stub(:find).with(mock_user.id){ mock_user }
+      get :show, :id => mock_user.id
       response.should be_success
     end
   end
spec/views/creations/show.html.erb_spec.rb
@@ -1,7 +1,18 @@
 require 'spec_helper'
 
 describe "creations/show.html.erb" do
+  include Devise::TestHelpers
+
+  def mock_user(stubs={})
+    @mock_user ||= mock_model(User, stubs).as_null_object
+  end
+
+  def mock_creation(stubs={})
+    @mock_creation ||= mock_model(Creation, stubs).as_null_object
+  end
+
   before(:each) do
+    request.env['warden'] = mock(Warden, :authenticate => mock_user, :authenticate! => mock_user)
     @creation = assign(:creation, stub_model(Creation,
       :name => "Name",
       :story => "MyText"