Created
October 30, 2009 20:08
-
-
Save mhfs/222666 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
| require File.dirname(__FILE__) + '/../spec_helper' | |
| describe MailingsController, 'while secure controller' do | |
| configure_controller | |
| context 'and not logged in' do | |
| before(:each) do | |
| set_accounts | |
| destroy_user_session | |
| end | |
| it "should not access actions" do | |
| [:index, :new, :create].each do |action| | |
| get action | |
| response.should redirect_to login_path | |
| end | |
| [:show, :edit, :update, :destroy].each do |action| | |
| get action, :id => 1 | |
| response.should redirect_to login_path | |
| end | |
| end | |
| end | |
| end | |
| describe MailingsController, 'while having a authenticated user' do | |
| configure_controller | |
| before(:each) do | |
| set_accounts | |
| create_regular_user_session | |
| @mailing = @current_account.mailings.first | |
| @prohibited_mailing = @another_account.mailings.first | |
| end | |
| it "should have more than one account with mailings" do | |
| Account.should have_at_least(2).records | |
| Mailing.should have_at_least(3).records | |
| end | |
| it "should list 2 fixtures for the current account" do | |
| get :index | |
| assigns[:mailings].size.should == 2 | |
| response.should be_success | |
| response.should render_template :index | |
| @current_account.mailings.each do |mailing| | |
| response.should contain mailing.subject | |
| end | |
| end | |
| it "should show mailing of current account" do | |
| get :show, :id => @mailing | |
| response.should be_success | |
| response.should render_template :show | |
| response.should contain @mailing.subject | |
| end | |
| it "should raise error if trying to view mailing of another account" do | |
| lambda { | |
| get :show, :id => @prohibited_mailing | |
| }.should raise_error ActiveRecord::RecordNotFound | |
| end | |
| it "should render new form for new action" do | |
| get :new | |
| response.should be_success | |
| response.should render_template :new | |
| response.should have_tag "form[action=?]", mailings_path | |
| end | |
| it "should render new template for create action when model is invalid" do | |
| @mailing.stub!(:valid?).and_return(false) | |
| @current_account.stub_association!(:mailings, :build => @mailing) | |
| post :create | |
| response.should be_success | |
| response.should render_template(:new) | |
| end | |
| it "should redirect to mailing details for create action when model is valid" do | |
| @mailing.stub!(:valid?).and_return(true) | |
| @current_account.stub_association!(:mailings, :build => @mailing) | |
| post :create | |
| flash[:notice].should_not be_nil | |
| response.should redirect_to mailing_path(assigns[:mailing]) | |
| end | |
| it "should render edit form for edit action when accessing current account mailing" do | |
| get :edit, :id => @mailing | |
| response.should be_success | |
| response.should render_template :edit | |
| response.should have_tag "form[action=?]", mailing_path(@mailing) | |
| end | |
| it "should raise error if trying to edit an mailing of another account" do | |
| lambda{ | |
| get :edit, :id => @prohibited_mailing | |
| }.should raise_error ActiveRecord::RecordNotFound | |
| end | |
| it "should render edit form for update action when model is invalid" do | |
| @mailing.stub!(:update_attributes).and_return(false) | |
| @current_account.stub_association!(:mailings, :find => @mailing) | |
| put :update, :id => @mailing | |
| response.should be_success | |
| response.should render_template(:edit) | |
| response.should have_tag "form[action=?]", mailing_path(@mailing) | |
| end | |
| it "should redirect to mailing details for update action when model is valid" do | |
| @mailing.stub!(:update_attributes).and_return(true) | |
| @current_account.stub_association!(:mailings, :find => @mailing) | |
| post :update, :id => @mailing | |
| flash[:notice].should_not be_nil | |
| response.should redirect_to mailing_path(assigns[:mailing]) | |
| end | |
| it "should raise error if trying to update an mailing of another account" do | |
| lambda{ | |
| post :edit, :id => @prohibited_mailing | |
| }.should raise_error ActiveRecord::RecordNotFound | |
| end | |
| it "should destroy model for destroy action and redirect to mailings list" do | |
| mailing = @mailing | |
| delete :destroy, :id => mailing | |
| flash[:notice].should_not be_nil | |
| response.should redirect_to(mailings_url) | |
| Mailing.exists?(mailing.id).should be_false | |
| end | |
| it "should raise error if trying to delete an mailing of another account" do | |
| lambda{ | |
| delete :destroy, :id => @prohibited_mailing | |
| }.should raise_error ActiveRecord::RecordNotFound | |
| end | |
| it "should return mailing content for preview action" do | |
| get :preview, :id => @mailing | |
| response.should contain @mailing.content | |
| end | |
| it "should use mailing layout for preview action" do | |
| get :preview, :id => @mailing | |
| response.layout.should == 'layouts/mailing' | |
| end | |
| it "should call parsed_content preview for preview action" do | |
| @mailing.should_receive(:parsed_content) | |
| @current_account.stub_association!(:mailings, :find => @mailing) | |
| get :preview, :id => @mailing | |
| end | |
| it "should use preview template for preview action" do | |
| get :preview, :id => @mailing | |
| response.should render_template(:preview) | |
| end | |
| context "given a content to preview" do | |
| before(:each) do | |
| @content = 'sample_content' | |
| end | |
| it "should return content for edit_preview action" do | |
| get :edit_preview, :content => @content | |
| response.should contain @content | |
| end | |
| it "should use mailing layout for edit_preview action" do | |
| get :edit_preview, :content => @content | |
| response.layout.should == 'layouts/mailing' | |
| end | |
| it "should make use of parse_content for edit_preview action" do | |
| Mailing.should_receive(:parse_content).once.with(@content) | |
| get :edit_preview, :content => @content | |
| end | |
| it "should use preview template for edit_preview action" do | |
| get :edit_preview, :content => @content | |
| response.should render_template(:preview) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment