Skip to content

Commit

Permalink
Specs for API and channels
Browse files Browse the repository at this point in the history
* Adds spec for API controller and fixes channels controller spec

* Changes FactoryGirl definitions
  • Loading branch information
HashNuke committed Apr 2, 2012
1 parent 789bbe7 commit 60150e2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/apis_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ApisController < ApplicationController

def active_users
respond_to do |format|
format.js { render :json => ActiveUsers.all }
format.json { render :json => ActiveUsers.all }
end
end
end
19 changes: 19 additions & 0 deletions spec/controllers/apis_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "spec_helper"

describe ApisController do

before :each do
@user = Factory :user
request.env['warden'].stub :authenticate! => @user
controller.stub :current_user => @user
end


describe "active_users" do
it "should return json" do
get :active_users, :format => :json
ActiveUsers.stub!(:all).and_return([])
JSON(response.body).should be_kind_of(Array)
end
end
end
11 changes: 7 additions & 4 deletions spec/controllers/channels_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

before :all do
@channel = Factory :channel
# @sample_activity = @channel.activities.build :action => "message"
end

before :each do
@user = Factory :user
request.env['warden'].stub :authenticate! => @user
controller.stub :current_user => @user
end

describe "GET index" do
it "should return list of channels in JSON" do
get :index, :format => :json
JSON(response.body).should be_kind_of(Array)
JSON(response.body).first.should have_key("activities")
JSON(response.body) # parse to validate json
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)
end
end

Expand Down
32 changes: 17 additions & 15 deletions spec/factories.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
Factory.sequence :ido_id do |n|
"abc-#{ n }"
end
FactoryGirl.define do
sequence :ido_id do |n|
"abc-#{n}"
end

Factory.sequence :email do |n|
"email#{ n }@factory.com"
end
sequence :email do |n|
"email#{n}@example.com"
end

Factory.define :channel do |f|
f.name "Test channel"
end
factory :channel do |f|
f.name "Test channel"
end

Factory.define :user do |f|
f.first_name "Test"
f.last_name "User"
f.email { Factory.next(:email) }
f.ido_id { Factory.next(:ido_id) }
end
factory :user do |f|
f.first_name "Test"
f.last_name "User"
f.email { Factory.next(:email) }
f.ido_id { Factory.next(:ido_id) }
end
end
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
ENV["RAILS_ENV"] = 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require "#{Rails.root}/lib/active_users.rb"

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Expand Down

0 comments on commit 60150e2

Please sign in to comment.