Last active
December 26, 2015 08:09
-
-
Save cupakromer/7120458 to your computer and use it in GitHub Desktop.
Controller test with shared example
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' | |
describe DashboardController do | |
include Factories::Godzilla | |
shared_examples "successfully gets the session cards" do | |
it "is successful" do | |
get :session_cards | |
expect(response).to be_success | |
end | |
it "renders no layout" do | |
get :session_cards | |
expect(response).to have_rendered layout: false | |
end | |
it "renders the card template" do | |
get :session_cards | |
expect(response).to have_rendered :session_cards | |
end | |
end | |
context "with no active sessions" do | |
before do | |
allow(DeviceSession).to receive(:active_by_company).and_return({}) | |
end | |
has_behavior "successfully gets the session cards" do | |
it "assigns no company sessions" do | |
get :session_cards | |
expect(assigns(:company_sessions)).to eq Hash.new | |
end | |
end | |
end | |
context "with active sessions" do | |
let(:active) { double(Hash) } | |
before do | |
allow(DeviceSession).to receive(:active_by_company).and_return(active) | |
end | |
has_behavior "successfully gets the session cards" do | |
it "assigns no company sessions" do | |
get :session_cards | |
expect(assigns(:company_sessions)).to eq active | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment