Skip to content

Commit

Permalink
cleaned up specs for merging event calendar into CMS
Browse files Browse the repository at this point in the history
  • Loading branch information
jlapier committed Nov 11, 2011
1 parent 3bbf926 commit 999eff1
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -30,6 +30,7 @@ class ApplicationController < ActionController::Base
# returns false for anonymous requests to non public resources
# returns result from can? for authenticated requests to non public resources
def has_authorization?(*args)
puts "in has auth"
return true if public_resource?(*args)
return false unless current_user

Expand Down Expand Up @@ -61,7 +62,7 @@ def in_file_share?

def protect_event_calendar
# allow all users to view events
unless controller_name == "events" && READ_ACTIONS.include?(action_name)
if controller_name == "events" and not READ_ACTIONS.include?(action_name)
return require_admin_user
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/blog/comments_controller.rb
Expand Up @@ -35,4 +35,4 @@ def destroy
redirect_to blog_dashboard_path, :notice => "Comment deleted!"
end
end
end
end
2 changes: 2 additions & 0 deletions config/initializers/constants.rb
@@ -0,0 +1,2 @@
TIME_BASE = '%I:%M %p'

4 changes: 4 additions & 0 deletions spec/controllers/blog/comments_controller_spec.rb
Expand Up @@ -7,6 +7,10 @@
let(:blog_post) do
stub_model(Blog::Post)
end
before(:each) do
controller.stub(:require_user){ mock_user }
controller.stub(:current_user){ mock_user }
end

describe "requiring authorization" do
before(:each) do
Expand Down
7 changes: 5 additions & 2 deletions spec/controllers/content_pages_controller_spec.rb
Expand Up @@ -90,8 +90,10 @@ def mock_content_page(stubs={}, new_mock = false)
end

it "re-renders the 'new' template" do
ContentPage.stub!(:new).and_return(mock_content_page(:save => false))
ContentPage.stub!(:new).and_return(mock_content_page)
mock_content_page.stub(:save).and_return(false)
post :create, :content_page => {}
puts flash
response.should render_template('new')
end
end
Expand Down Expand Up @@ -134,7 +136,8 @@ def mock_content_page(stubs={}, new_mock = false)
end

it "re-renders the 'edit' template" do
ContentPage.stub!(:find).and_return(mock_content_page(:update_attributes => false))
ContentPage.stub!(:find).and_return(mock_content_page)
mock_content_page.stub(:update_attributes).and_return(false)
put :update, :id => "1"
response.should render_template('edit')
end
Expand Down
3 changes: 3 additions & 0 deletions spec/controllers/event_calendar/attendees_controller_spec.rb
Expand Up @@ -3,6 +3,8 @@
describe EventCalendar::AttendeesController do
describe ":index, :event_id => required" do
before(:each) do
controller.stub(:require_user){ mock_user }
controller.stub(:current_user){ mock_user }
EventCalendar::Event.stub(:find).and_return(mock_event)
class FakeModel
extend ActiveModel::Naming
Expand All @@ -17,6 +19,7 @@ def self.find(*args)

it "loads an @event" do
get :index, :event_id => "1"
response.should be_success
assigns[:event].should eql mock_event
end
it "renders the attendees template" do
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/themes_controller_spec.rb
Expand Up @@ -10,7 +10,7 @@

describe "GET 'colors'" do
it "should be successful" do
get 'colors', :format => :css
get :colors, :format => :css
response.should be_success
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/helpers/application_helper_spec.rb
Expand Up @@ -55,7 +55,7 @@ def mock_admin_user(stubs={})

it "should have a user box with a log in link" do
# avoid MethodMissing for link_to_events
helper.class.send :include, EventCalendar::ApplicationHelper
helper.class.send :include, EventCalendar::EventsHelper
helper.stub(:current_user).and_return(nil)
helper.user_box.should =~ (/Log In/)
helper.user_box.should =~ (/Register/)
Expand Down Expand Up @@ -103,18 +103,18 @@ def mock_admin_user(stubs={})
end

it "should have a user box with link to events calendar when the user is logged in" do
helper.class.send :include, EventCalendar::ApplicationHelper
helper.class.send :include, EventCalendar::EventsHelper
helper.stub(:current_user).and_return(mock_admin_user)
helper.user_box.should =~ /Events/
helper.user_box.should =~ /href="\/events"/
helper.user_box.should =~ /href="\/event_calendar\/events"/
end

it "should have a user box with link to events calendar when the user is logged out" do
helper.class.send :include, EventCalendar::ApplicationHelper
helper.class.send :include, EventCalendar::EventsHelper
helper.stub(:current_user).and_return(nil)
helper.stub(:public_resource?).and_return(true)
helper.user_box.should =~ /Events/
helper.user_box.should =~ /href="\/events"/
helper.user_box.should =~ /href="\/event_calendar\/events"/
end

it "should give a list of images" do
Expand Down
1 change: 1 addition & 0 deletions spec/support/helpers.rb
Expand Up @@ -23,6 +23,7 @@ def mock_event(stubs={})

def mock_user(stubs={})
@mock_user ||= mock_model(User, stubs.merge({:is_admin? => true,
:logged_in? => true,
:has_read_access_to? => true, :has_write_access_to? => true}))
end

0 comments on commit 999eff1

Please sign in to comment.