Created
September 12, 2008 19:18
-
-
Save joshuaclayton/10502 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "handling actions when a user doesn't have access" do | |
def before_each | |
login_with(:sales_rep) | |
@quote = mock("QuotePresenter", :current_user_has_access? => false, :full_name => "test") | |
QuotePresenter.stub!(:new).and_return(@quote) | |
current_user.stub!(:quotes).and_return([@quote]) | |
current_user.quotes.stub!(:find).and_return(@quote) | |
end | |
def self.unsuccessful_attempt(v) | |
%{ | |
describe "handling #{v[:route]} without access" do | |
before(:each) do | |
before_each | |
end | |
it "should not be successful" do | |
#{v[:action]} | |
response.response_code.should == 401 | |
end | |
#{ | |
if v[:template] | |
"it \"should not render #{v[:template]} template\" do | |
#{v[:action]} | |
response.should_not render_template('#{v[:template]}') | |
end" | |
end | |
} | |
end | |
} | |
end | |
instance_eval unsuccessful_attempt({:route => "GET /quotes/1", :action => 'get :show, :id => "1"', :template => "show"}) | |
instance_eval unsuccessful_attempt({:route => "DELETE /quotes/1", :action => 'delete :destroy, :id => "1"'}) | |
instance_eval unsuccessful_attempt({:route => "PUT /quotes/1", :action => 'put :update, :id => "1"'}) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../spec_helper' | |
describe ::FoldersController do | |
describe "handle GET /folders" do | |
def before_each | |
login_with(:has_account) | |
@folder = mock_model(Folder) | |
Folder.stub!(:roots).and_return([@folder]) | |
end | |
instance_eval successful_index(:model => "folder", :find => "Folder.should_receive(:roots).and_return([@folder])") | |
end | |
describe "handling GET /folders.xml" do | |
def before_each | |
login_with(:has_account) | |
@folder = mock_model(Folder, :to_xml => "XML") | |
Folder.stub!(:roots).and_return(@folder) | |
end | |
instance_eval successful_index_xml(:model => "folder", :find => "Folder.should_receive(:roots).and_return([@folder])") | |
end | |
describe "handling GET /folders/1" do | |
def before_each | |
login_with(:has_account) | |
@folder = mock_model(Folder, :name => "Folder") | |
@folder.stub!(:child_items).and_return([]) | |
@folder.stub!(:hierarchy).and_return([@folder]) | |
Folder.stub!(:find).and_return(@folder) | |
end | |
instance_eval successful_get(:model => "folder", :find => "Folder.should_receive(:find).with('1').and_return(@folder)"), __FILE__, __LINE__ | |
end | |
describe "handling GET /folders/1.xml" do | |
def before_each | |
login_with(:has_account) | |
@folder = mock_model(Folder, :to_xml => "XML", :name => "Folder") | |
@folder.stub!(:child_items).and_return([]) | |
@folder.stub!(:hierarchy).and_return([@folder]) | |
Folder.stub!(:find).and_return(@folder) | |
end | |
instance_eval successful_get_xml(:model => "folder", :find => "Folder.should_receive(:find).with('1').and_return(@folder)"), __FILE__, __LINE__ | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/../spec_helper' | |
describe ::FoldersController do | |
describe "handling GET /folders" do | |
before(:each) do | |
login_with(:has_account) | |
@folder = mock_model(Folder) | |
Folder.stub!(:roots).and_return([@folder]) | |
end | |
def do_get | |
get :index | |
end | |
it "should be successful" do | |
do_get | |
response.should be_success | |
end | |
it "should render index template" do | |
do_get | |
response.should render_template('index') | |
end | |
it "should find all folders" do | |
Folder.should_receive(:roots).and_return([@folder]) | |
do_get | |
end | |
it "should assign the found folders for the view" do | |
do_get | |
assigns[:folders].should == [@folder] | |
end | |
end | |
describe "handling GET /folders.xml" do | |
before(:each) do | |
login_with(:has_account) | |
@folder = mock_model(Folder, :to_xml => "XML") | |
Folder.stub!(:roots).and_return(@folder) | |
end | |
def do_get | |
@request.env["HTTP_ACCEPT"] = "application/xml" | |
get :index | |
end | |
it "should be successful" do | |
do_get | |
response.should be_success | |
end | |
it "should find all folders" do | |
Folder.should_receive(:roots).and_return([@folder]) | |
do_get | |
end | |
it "should render the found folders as xml" do | |
@folder.should_receive(:to_xml).and_return("XML") | |
do_get | |
response.body.should == "XML" | |
end | |
end | |
describe "handling GET /folders/1" do | |
before(:each) do | |
login_with(:has_account) | |
@folder = mock_model(Folder, :name => "Folder") | |
@folder.stub!(:child_items).and_return([]) | |
@folder.stub!(:hierarchy).and_return([@folder]) | |
Folder.stub!(:find).and_return(@folder) | |
end | |
def do_get | |
get :show, :id => "1" | |
end | |
it "should be successful" do | |
do_get | |
response.should be_success | |
end | |
it "should render show template" do | |
do_get | |
response.should render_template('show') | |
end | |
it "should find the folder requested" do | |
Folder.should_receive(:find).with("1").and_return(@folder) | |
do_get | |
end | |
it "should assign the found folder for the view" do | |
do_get | |
assigns[:folder].should equal(@folder) | |
end | |
end | |
describe "handling GET /folders/1.xml" do | |
before(:each) do | |
login_with(:has_account) | |
@folder = mock_model(Folder, :to_xml => "XML", :name => "Folder") | |
@folder.stub!(:child_items).and_return([]) | |
@folder.stub!(:hierarchy).and_return([@folder]) | |
Folder.stub!(:find).and_return(@folder) | |
end | |
def do_get | |
@request.env["HTTP_ACCEPT"] = "application/xml" | |
get :show, :id => "1" | |
end | |
it "should be successful" do | |
do_get | |
response.should be_success | |
end | |
it "should find the folder requested" do | |
Folder.should_receive(:find).with("1").and_return(@folder) | |
do_get | |
end | |
it "should render the found folder as xml" do | |
@folder.should_receive(:to_xml).and_return("XML") | |
do_get | |
response.body.should == "XML" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment