Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Changed up the before blocks, calling methods to many times
  • Loading branch information
amanelis committed Jan 24, 2013
1 parent 6c790fa commit 827cde1
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions spec/controllers/channels_controller_spec.rb
@@ -1,57 +1,69 @@
require "spec_helper"

describe ChannelsController do
before :all do
include Devise::TestHelpers

before(:all) do
@channel = FactoryGirl.create(:channel)
@user = FactoryGirl.create(:user)
end

before :each do
@user = FactoryGirl.create(:user)
request.env['warden'].stub :authenticate! => @user
controller.stub :current_user => @user
before(:each) do
sign_in @user
end

describe "GET index" do
it "should return list of channels in JSON" do
before do
get :index, :format => :json
JSON(response.body) # parse to validate json
end

it "should return list of channels in JSON" do
expect(JSON(response.body)).to be_kind_of(Array)
end

it "should have an array for activities in the JSON response" do
get :index, :format => :json
puts JSON(response.body).first["activities"].should be_kind_of(Array)
expect(JSON(response.body).first["activities"]).to be_kind_of(Array)
end
end

describe "GET show" do
it "should return the channel data in json" do
before do
get :show, :id => @channel.id, :format => :json
response.should be_ok
end

it "should return the channel data in json" do
expect(response).to be_ok
end
end

describe "POST create" do
describe "POST create" do
before do
channel = { :name => Faker::Internet.domain_word }
post :create, :channel => channel, :format => :json
end

it "should create a channel" do
channel_attributes = Factory.build :channel
Channel.any_instance.should_receive(:save)
post :create, :format => :json
expect(response.status).to eq(201)
end
end

describe "PUT update" do
it "should update the channel" do
# Channel.any_instance.should_receive(:update_attributes)
before do
put :update, :id => @channel.id, :channel => {:name => "SuperTest"}, :format => :json
response.should be_ok
end

it "should update the channel" do
expect(response.status).to eq(200)
end
end

describe "DELETE destroy" do
it "should destroy the channel" do
# Channel.any_instance.should_receive(:destroy)
before do
delete :destroy, :id => @channel.id, :format => :json
response.should be_ok
end

it "should destroy the channel" do
expect(response.status).to eq(200)
end
end

end
end

0 comments on commit 827cde1

Please sign in to comment.