Created
September 7, 2012 03:12
-
-
Save stevencwarren/3662770 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 'spec_helper.rb' | |
| describe ArticlesController do | |
| describe 'GET index' do | |
| before(:each) do | |
| 10.times do |i| | |
| Factory(:article, :title => "Article #{i}") | |
| end | |
| @unpublished_article = Factory(:article, :title => "Unpublished Article", :published_at => Date.tomorrow) | |
| get :index | |
| end | |
| it "should assign articles" do | |
| assigns(:resources).should_not be_empty | |
| end | |
| it "should have 10 published articles" do | |
| assigns(:resources).count.should == 10 | |
| end | |
| it "should render the resources/index template" do | |
| response.should render_template("resources/index") | |
| end | |
| it 'should not show articles who have not been published yet' do | |
| assigns(:resources).should_not include(@unpublished_article) | |
| end | |
| end | |
| describe 'GET show' do | |
| before :each do | |
| @article = Factory(:article) | |
| @unpublished_article = Factory(:article, :title => 'Unpublished Article', :published_at => Date.tomorrow) | |
| activate_authlogic | |
| end | |
| context 'when not signed in' do | |
| it 'should show me a published article' do | |
| get :show, :id => @article.slug | |
| assigns(:resource).should == @article | |
| end | |
| it 'should not let me access an unpublished article' do | |
| get :show, :id => @unpublished_article.slug | |
| assigns(:resource).should be_nil | |
| end | |
| end | |
| context 'when signed-in as a non-admin user' do | |
| before :each do | |
| @user = Factory(:user) | |
| UserSession.create(@user) | |
| end | |
| it 'should show me a published article' do | |
| get :show, :id => @article.slug | |
| assigns(:resource).should == @article | |
| end | |
| it 'should not let me access an unpublished article' do | |
| get :show, :id => @unpublished_article.slug | |
| assigns(:resource).should be_nil | |
| end | |
| end | |
| context 'when signed-in as a content admin user' do | |
| before :each do | |
| @user = Factory(:content_admin) | |
| UserSession.create(@user) | |
| end | |
| it 'should show me a published article' do | |
| get :show, :id => @article.slug | |
| assigns(:resource).should == @article | |
| end | |
| it 'should let me access an unpublished article' do | |
| get :show, :id => @unpublished_article.slug | |
| assigns(:resource).should == @unpublished_article | |
| end | |
| end | |
| context 'when signed-in as a super admin user' do | |
| before :each do | |
| @user = Factory(:super_admin) | |
| UserSession.create(@user) | |
| end | |
| it 'should show me a published article' do | |
| get :show, :id => @article.slug | |
| assigns(:resource).should == @article | |
| end | |
| it 'should let me access an unpublished article' do | |
| get :show, :id => @unpublished_article.slug | |
| assigns(:resource).should == @unpublished_article | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment