Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Merge pull request #43 from snap-cloud/rspec-update
Browse files Browse the repository at this point in the history
Rspec update
  • Loading branch information
cycomachead committed Apr 22, 2015
2 parents 79fae96 + 1e55726 commit d2d1898
Show file tree
Hide file tree
Showing 19 changed files with 205 additions and 104 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ gem 'rack-cache'
group :development, :test do
# Cucumber, testing and coverage
gem 'cucumber-rails', :require => false
gem 'rspec-rails', '~> 2.14.0'
gem 'rspec-rails', '>= 3.1'
gem 'simplecov'
gem "factory_girl_rails"
gem 'faker'
Expand Down
31 changes: 18 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,23 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-rails (2.14.2)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (3.2.3)
rspec-support (~> 3.2.0)
rspec-expectations (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-mocks (3.2.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.2.0)
rspec-rails (3.2.1)
actionpack (>= 3.0, < 4.3)
activesupport (>= 3.0, < 4.3)
railties (>= 3.0, < 4.3)
rspec-core (~> 3.2.0)
rspec-expectations (~> 3.2.0)
rspec-mocks (~> 3.2.0)
rspec-support (~> 3.2.0)
rspec-support (3.2.2)
ruby2ruby (2.1.3)
ruby_parser (~> 3.1)
sexp_processor (~> 4.0)
Expand Down Expand Up @@ -301,7 +306,7 @@ DEPENDENCIES
rack-cache
rails (= 4.2.1)
rails_12factor
rspec-rails (~> 2.14.0)
rspec-rails (>= 3.1)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
shoulda-matchers
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/api_constrains_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe ApiConstraints do
let(:api_constraints_v1) { ApiConstraints.new(version: 1) }
Expand Down
44 changes: 18 additions & 26 deletions spec/controllers/api/v1/projects_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
require 'api/v1/projects_controller'


Expand All @@ -14,7 +14,7 @@
allow(request.env['warden']).to receive(:authenticate!).and_return(fakeuser)
allow(controller).to receive(:current_user).and_return(fakeuser)

get :show, id: @project.id, format: :json
get :show, id: @project.id
end

it { should respond_with 200 }
Expand All @@ -38,14 +38,14 @@
proj = Project.create(title: "Test proj", owner:user.id)
Project.any_instance.should_receive(:update_attributes)
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user)
put :update, { project_params: proj.attributes, id:proj.id }, format: :json
put :update, { project_params: proj.attributes, id:proj.id }
expect(response.status).to eq(204)
end

it "should reject the request when I am not logged in" do
proj = Project.create(title: "Test proj")
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(nil)
put :update, { project_params: proj.attributes, id:proj.id}, format: :json
put :update, { project_params: proj.attributes, id:proj.id}
expect(response.status).to eq(401)
end

Expand All @@ -54,15 +54,15 @@
not_users_id = user.id+1
proj = Project.create(title: "Test proj", owner:(not_users_id))
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user)
put :update, { project_params: proj.attributes, id:proj.id }, format: :json
put :update, { project_params: proj.attributes, id:proj.id }
expect(response.status).to eq(401)
end

it "should reject the request when the project doesn't exist" do
user = User.create(email: "[email protected]")
proj = Project.create(title: "Test proj", owner:user.id)
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user)
put :update, { project_params: proj.attributes, id:(proj.id+1) }, format: :json
put :update, { project_params: proj.attributes, id:(proj.id+1) }
expect(response.status).to eq(404)
end
end
Expand All @@ -83,12 +83,9 @@
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user1)

post :create, {project_params: {title: "test proj for user 1", owner:user1.id}}
expect(response.status).to eq(200) #:ok
expect(response.status).to eq(200)
end




end

describe "DELETE #destroy" do
Expand All @@ -109,22 +106,19 @@
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user1)
user1_proj = Project.create(title: "user1 proj", owner:user1.id)

delete :destroy, {id: user1_proj.id}
#project_response = JSON.parse(response.body, symbolize_names: true)
## response is populated with last response; last line is unnecessary for now
expect(response.status).to eq(200) #:ok
delete :destroy, { id: user1_proj.id }
expect(response.status).to eq(200)
end

it "should reject the request if user is not an owner" do
user1 = User.create(email: "[email protected]")
user2 = User.create(email: "[email protected]")
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(user2)
user1_proj = Project.create(title: "user1 proj", owner:user1.id)
user1_proj = Project.create(title: "user1 proj", owner: user1.id)

delete :destroy, {id: user1_proj.id}
#project_response = JSON.parse(response.body, symbolize_names: true)
## response is populated with last response; last line is unnecessary for now
expect(response.status).to eq(401) #:unauthorized
delete :destroy, { id: user1_proj.id }
# FIXME -- Should probably be a 404.
expect(response.status).to eq(401)
end
end

Expand All @@ -148,23 +142,23 @@
proj2 = Project.create(title: "user private", owner:user.id, is_public: 0)
proj3 = Project.create(title: "nonuser public", owner:not_users_id, is_public: 1)
proj4 = Project.create(title: "nonuser private", owner:not_users_id, is_public: 0)
get :index, {user_id: user.id}, format: :json
get :index, {user_id: user.id}
project_response = JSON.parse(response.body, symbolize_names: true)

expect(project_response.length).to eq(2)
expect(project_response[0][:title]).to eq("user public")
expect(project_response[1][:title]).to eq("user private")
end

it "Should show only public projects if user not logged in" do
it "should show only public projects if user not logged in" do
user = User.create(email: "[email protected]")
not_users_id = user.id+1
Api::V1::ProjectsController.any_instance.stub(:getCurrentUser).and_return(nil)
proj1 = Project.create(title: "user public", owner:user.id, is_public: 1)
proj2 = Project.create(title: "user private", owner:user.id, is_public: 0)
proj3 = Project.create(title: "nonuser public", owner:not_users_id, is_public: 1)
proj4 = Project.create(title: "nonuser private", owner:not_users_id, is_public: 0)
get :index, {user_id: user.id}, format: :json
get :index, {user_id: user.id}
project_response = JSON.parse(response.body, symbolize_names: true)
expect(project_response.length).to eq(1)
expect(project_response[0][:title]).to eq("user public")
Expand All @@ -177,8 +171,7 @@
# before(:each) do
# @project = FactoryGirl.create :project
# patch :update, { id: @project.id,
# project: { title: "new title" } }, format: :json
# end
# project: { title: "new title" } } # end

# it "renders the json representation for the updated project" do
# project_response = JSON.parse(response.body, symbolize_names: true)
Expand All @@ -192,8 +185,7 @@
# before(:each) do
# @project = FactoryGirl.create :project
# patch :update, { id: @project.id,
# project: { title: "bad title" } }, format: :json
# end
# project: { title: "bad title" } } # end

# it "renders an errors json" do
# project_response = JSON.parse(response.body, symbolize_names: true)
Expand Down
20 changes: 9 additions & 11 deletions spec/controllers/api/v1/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'spec_helper'
require 'rails_helper'
require 'sessions_controller'
require 'registrations_controller'
require 'api/v1/users_controller'

describe Api::V1::UsersController do

before(:each) { request.headers['Accept'] = "application/json" }

describe "GET #show" do
Expand All @@ -14,7 +14,7 @@
allow(controller).to receive(:current_user).and_return(fakeuser)

@user = FactoryGirl.create :user
get :show, id: @user.id, format: :json
get :show, id: @user.id

end

Expand All @@ -35,7 +35,7 @@
allow(request.env['warden']).to receive(:authenticate!).and_return(fakeuser)
allow(controller).to receive(:current_user).and_return(fakeuser)

post :create, { user: @user_attrs }, format: :json
post :create, { user: @user_attrs }
end

it "renders the json representation for the user record just created" do
Expand All @@ -57,7 +57,7 @@
allow(controller).to receive(:current_user).and_return(fakeuser)


post :create, { user: @invalid_user_attributes }, format: :json
post :create, { user: @invalid_user_attributes }
end

it "renders json with errors" do
Expand All @@ -82,11 +82,10 @@
allow(request.env['warden']).to receive(:authenticate!).and_return(fakeuser)
allow(controller).to receive(:current_user).and_return(fakeuser)

delete :destroy, { id: @user.id }, format: :json
delete :destroy, { id: @user.id }
end

it { should respond_with 204 }

end

describe "PUT/PATCH #update" do
Expand All @@ -100,7 +99,7 @@
allow(controller).to receive(:current_user).and_return(fakeuser)

patch :update, { id: @user.id,
user: { email: "[email protected]" } }, format: :json
user: { email: "[email protected]" } }

end

Expand All @@ -121,11 +120,10 @@
allow(controller).to receive(:current_user).and_return(fakeuser)


patch :update, { id: @user.id,
user: { email: "bademail.com" } }, format: :json
patch :update, { id: @user.id, user: { email: "bademail.com" } }
end

it "renders an errors json" do
it "rendered json with errors" do
user_response = JSON.parse(response.body, symbolize_names: true)
expect(user_response).to have_key(:errors)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/assignments_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe AssignmentsController do

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/courses_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
require 'spec_helper'
require 'rails_helper'
4 changes: 2 additions & 2 deletions spec/controllers/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'spec_helper'
require 'rails_helper'

describe PagesController do

describe "GET 'index'" do
it "returns http success" do
get 'index'
response.should be_success
expect(response).to be_success
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/projects_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe ProjectsController do

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/submissions_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe SubmissionsController do

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/user_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe UsersController do

Expand Down
2 changes: 1 addition & 1 deletion spec/models/announcement_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe Announcement do
pending "add some examples to (or delete) #{__FILE__}"
Expand Down
2 changes: 1 addition & 1 deletion spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe Assignment do
pending "add some examples to (or delete) #{__FILE__}"
Expand Down
2 changes: 1 addition & 1 deletion spec/models/course_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe Course do
describe "#students" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/enrollment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe Enrollment do
pending "add some examples to (or delete) #{__FILE__}"
Expand Down
2 changes: 1 addition & 1 deletion spec/models/project_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe Project do
before { @project = FactoryGirl.build(:project) }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'

describe User do
before { @user = FactoryGirl.build(:user) }
Expand Down
Loading

0 comments on commit d2d1898

Please sign in to comment.