Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Changed up the before blocks, calling methods to many times
- Loading branch information
Showing
1 changed file
with
35 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |