Skip to content

Commit 60150e2

Browse files
committedApr 2, 2012
Specs for API and channels
* Adds spec for API controller and fixes channels controller spec * Changes FactoryGirl definitions
1 parent 789bbe7 commit 60150e2

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed
 

‎app/controllers/apis_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ApisController < ApplicationController
44

55
def active_users
66
respond_to do |format|
7-
format.js { render :json => ActiveUsers.all }
7+
format.json { render :json => ActiveUsers.all }
88
end
99
end
1010
end
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "spec_helper"
2+
3+
describe ApisController do
4+
5+
before :each do
6+
@user = Factory :user
7+
request.env['warden'].stub :authenticate! => @user
8+
controller.stub :current_user => @user
9+
end
10+
11+
12+
describe "active_users" do
13+
it "should return json" do
14+
get :active_users, :format => :json
15+
ActiveUsers.stub!(:all).and_return([])
16+
JSON(response.body).should be_kind_of(Array)
17+
end
18+
end
19+
end

‎spec/controllers/channels_controller_spec.rb

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@
44

55
before :all do
66
@channel = Factory :channel
7-
# @sample_activity = @channel.activities.build :action => "message"
87
end
98

109
before :each do
1110
@user = Factory :user
1211
request.env['warden'].stub :authenticate! => @user
1312
controller.stub :current_user => @user
1413
end
15-
14+
1615
describe "GET index" do
1716
it "should return list of channels in JSON" do
1817
get :index, :format => :json
19-
JSON(response.body).should be_kind_of(Array)
20-
JSON(response.body).first.should have_key("activities")
18+
JSON(response.body) # parse to validate json
19+
end
20+
21+
it "should have an array for activities in the JSON response" do
22+
get :index, :format => :json
23+
puts JSON(response.body).first["activities"].should be_kind_of(Array)
2124
end
2225
end
2326

‎spec/factories.rb

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
Factory.sequence :ido_id do |n|
2-
"abc-#{ n }"
3-
end
1+
FactoryGirl.define do
2+
sequence :ido_id do |n|
3+
"abc-#{n}"
4+
end
45

5-
Factory.sequence :email do |n|
6-
"email#{ n }@factory.com"
7-
end
6+
sequence :email do |n|
7+
"email#{n}@example.com"
8+
end
89

9-
Factory.define :channel do |f|
10-
f.name "Test channel"
11-
end
10+
factory :channel do |f|
11+
f.name "Test channel"
12+
end
1213

13-
Factory.define :user do |f|
14-
f.first_name "Test"
15-
f.last_name "User"
16-
f.email { Factory.next(:email) }
17-
f.ido_id { Factory.next(:ido_id) }
18-
end
14+
factory :user do |f|
15+
f.first_name "Test"
16+
f.last_name "User"
17+
f.email { Factory.next(:email) }
18+
f.ido_id { Factory.next(:ido_id) }
19+
end
20+
end

‎spec/spec_helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# This file is copied to spec/ when you run 'rails generate rspec:install'
2-
ENV["RAILS_ENV"] ||= 'test'
2+
ENV["RAILS_ENV"] = 'test'
33
require File.expand_path("../../config/environment", __FILE__)
44
require 'rspec/rails'
55
require 'rspec/autorun'
6+
require "#{Rails.root}/lib/active_users.rb"
67

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

0 commit comments

Comments
 (0)
Please sign in to comment.