Skip to content

Commit

Permalink
Merge pull request #5 from amanelis/spec-updates
Browse files Browse the repository at this point in the history
Spec updates, gem updates, lots more.
  • Loading branch information
jrgifford committed Jan 24, 2013
2 parents 253a030 + 350dde9 commit 4d770f5
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 102 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,6 +14,7 @@
/app/assets/stylesheets/.sass-cache

.bushido
.rvmrc

/public/assets

Expand Down
38 changes: 23 additions & 15 deletions Gemfile
Expand Up @@ -3,15 +3,8 @@ source 'https://rubygems.org'
# Core gems
gem 'rails', '3.2.11'

group :development, :test do
gem 'sqlite3'
gem 'guard'
gem 'guard-rspec'
end
# Database adapters
gem 'pg', '0.12.2'
# Uncomment this is you want to use sqlite locally
# gem 'sqlite3'
gem 'pg'

# Auth/Cloudfuji gems
gem 'devise'
Expand All @@ -35,18 +28,33 @@ gem 'airbrake'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'sass-rails'
gem 'coffee-rails'
gem 'bourbon'
gem 'execjs' # See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'execjs'
gem 'eco'
gem 'uglifier', '>= 1.0.3'
gem 'uglifier'
end

group :development do
gem 'pry-rails'
gem 'quiet_assets'
gem 'awesome_print'
gem 'better_errors'
gem 'binding_of_caller'
end

# Test gems, obviously
group :test do
gem 'faker'
gem 'rspec-rails'
gem 'shoulda-matchers'
gem 'factory_girl_rails', '~> 3.0'
gem 'jasmine', :git => "https://github.com/pivotal/jasmine-gem.git", :branch => "1.2.rc1", :group => [:development, :test]
gem 'factory_girl_rails'
end

group :development, :test do
gem 'sqlite3'
gem 'guard'
gem 'guard-rspec'
gem 'database_cleaner'
gem 'jasmine', :git => 'https://github.com/pivotal/jasmine-gem.git', :branch => '1.2.rc1'
end
29 changes: 24 additions & 5 deletions Gemfile.lock
Expand Up @@ -53,12 +53,17 @@ GEM
activesupport
builder
arel (3.0.2)
awesome_print (1.1.0)
aws-sdk (1.3.8)
httparty (~> 0.7)
json (~> 1.4)
nokogiri (<= 1.5.0)
uuidtools (~> 2.1)
bcrypt-ruby (3.0.1)
better_errors (0.3.2)
coderay (>= 1.0.0)
erubis (>= 2.7.0)
binding_of_caller (0.6.8)
bourbon (1.4.0)
sass (>= 3.1)
bourne (1.1.2)
Expand Down Expand Up @@ -88,6 +93,7 @@ GEM
coffee-script-source (1.2.0)
cookiejar (0.3.0)
daemons (1.1.8)
database_cleaner (0.9.1)
devise (1.5.3)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.0.3)
Expand Down Expand Up @@ -115,6 +121,8 @@ GEM
factory_girl_rails (3.1.0)
factory_girl (~> 3.1.0)
railties (>= 3.0.0)
faker (1.1.2)
i18n (~> 0.5)
ffi (1.3.0)
guard (1.6.1)
listen (>= 0.6.0)
Expand Down Expand Up @@ -164,6 +172,10 @@ GEM
coderay (~> 1.0.5)
method_source (~> 0.8)
slop (~> 3.3.1)
pry-rails (0.2.2)
pry (>= 0.9.10)
quiet_assets (1.0.1)
railties (~> 3.1)
rack (1.4.3)
rack-cache (1.2)
rack (>= 0.4)
Expand Down Expand Up @@ -255,27 +267,34 @@ PLATFORMS
DEPENDENCIES
_bushido-faye (= 0.8.2)
airbrake
awesome_print
aws-sdk
better_errors
binding_of_caller
bourbon
cloudfuji
cloudfuji_paperclip
coffee-rails (~> 3.2.1)
coffee-rails
database_cleaner
devise
devise_cloudfuji_authenticatable
eco
execjs
factory_girl_rails (~> 3.0)
factory_girl_rails
faker
guard
guard-rspec
jasmine!
jquery-rails
kaminari
pg (= 0.12.2)
pg
pry-rails
quiet_assets
rails (= 3.2.11)
remotipart
rspec-rails
sass-rails (~> 3.2.3)
sass-rails
shoulda-matchers
sqlite3
thin
uglifier (>= 1.0.3)
uglifier
Binary file removed app/assets/images/rails.png
Binary file not shown.
3 changes: 1 addition & 2 deletions app/controllers/apis_controller.rb
@@ -1,5 +1,4 @@
class ApisController < ApplicationController

before_filter :authenticate_user!

def active_users
Expand All @@ -13,4 +12,4 @@ def me
format.json { render :json => current_user }
end
end
end
end
2 changes: 0 additions & 2 deletions config/application.rb
Expand Up @@ -26,8 +26,6 @@ class Application < Rails::Application
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.

config.assets.initialize_on_precompile = false

# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)

Expand Down
40 changes: 27 additions & 13 deletions spec/controllers/apis_controller_spec.rb
@@ -1,19 +1,33 @@
require "spec_helper"

describe ApisController do
include Devise::TestHelpers

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)
describe "#active_users" do
before do
@user = FactoryGirl.create(:user)
end

context "when a user is authenticated" do
before do
sign_in @user
get :active_users, :format => :json
end

it "should return json" do
ActiveUsers.stub!(:all).and_return([])
expect(JSON(response.body)).to be_kind_of(Array)
end
end

context "when a user is NOT authenticated" do
before do
get :active_users, :format => :json
end

it "should not render any data or anything other than a 401" do
expect(response.status).to eq(401)
end
end
end
end
end
61 changes: 36 additions & 25 deletions spec/controllers/channels_controller_spec.rb
@@ -1,58 +1,69 @@
require "spec_helper"

describe ChannelsController do

before :all do
@channel = Factory :channel
include Devise::TestHelpers

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

before :each do
@user = Factory :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
6 changes: 3 additions & 3 deletions spec/factories.rb
Expand Up @@ -18,8 +18,8 @@
factory :user do |f|
f.first_name "Test"
f.last_name "User"
f.password { Factory.next(:password)}
f.email { Factory.next(:email) }
f.ido_id { Factory.next(:ido_id) }
f.password { FactoryGirl.generate(:password)}
f.email { FactoryGirl.generate(:email) }
f.ido_id { FactoryGirl.generate(:ido_id) }
end
end
9 changes: 2 additions & 7 deletions spec/models/activity_spec.rb
Expand Up @@ -2,12 +2,7 @@

describe Activity do
describe "associations" do
it "should belong to user" do
should belong_to(:user)
end

it "should belong to channel" do
should belong_to(:channel)
end
it { should belong_to(:user) }
it { should belong_to(:channel) }
end
end
15 changes: 9 additions & 6 deletions spec/models/attachment_spec.rb
Expand Up @@ -2,12 +2,15 @@

describe Attachment do
describe "associations" do
it "should belong to channel" do
should belong_to(:channel)
end

it "should belong to user" do
should belong_to(:user)
it { should belong_to(:channel) }
it { should belong_to(:user) }
end

describe "#url" do
subject { double('attachment', url: 'some_string', file: 'file') }

it "should return a string file_name" do
expect(subject.url).to eq('some_string')
end
end
end
9 changes: 2 additions & 7 deletions spec/models/channel_spec.rb
Expand Up @@ -2,13 +2,8 @@

describe Channel do
describe "associations" do
it "should have many activities" do
should have_many(:activities)
end

it "should have many attachments" do
should have_many(:attachments)
end
it { should have_many(:activities) }
it { should have_many(:attachments) }
end

describe "user_connect" do
Expand Down

0 comments on commit 4d770f5

Please sign in to comment.