diff options
| author | mo khan <mo@mokhan.ca> | 2015-01-27 22:40:39 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-01-27 22:54:50 -0700 |
| commit | 68c0a36cddc17f2086002675e3c8ee999cc1cc30 (patch) | |
| tree | 762b0f586e0d4611fb3e38c72bf393bf4fe62ab6 /spec/controllers/api | |
| parent | 0c018dc5332c513d538918858830e5eaa47b0691 (diff) | |
happy hound.
Diffstat (limited to 'spec/controllers/api')
9 files changed, 83 insertions, 70 deletions
diff --git a/spec/controllers/api/v1/cakes_controller_spec.rb b/spec/controllers/api/v1/cakes_controller_spec.rb index b3d1f221..e0cb3a64 100644 --- a/spec/controllers/api/v1/cakes_controller_spec.rb +++ b/spec/controllers/api/v1/cakes_controller_spec.rb @@ -7,7 +7,7 @@ describe Api::V1::CakesController do let(:user) { create(:user) } before :each do - request.env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token) + api_login(user) end describe "#index" do @@ -58,10 +58,11 @@ describe Api::V1::CakesController do let(:cake) { create(:cake, user: user) } it "tags the cake" do - xhr :patch, :update, id: cake.id, cake: { tags: "cake, cookies, yummy" } + tags = ["cake", "cookies", "yummy"] + xhr :patch, :update, id: cake.id, cake: { tags: tags.join(", ") } cake.reload - expect(cake.tags.pluck(:name)).to match_array(["cake", "cookies", "yummy"]) + expect(cake.tags.pluck(:name)).to match_array(tags) end it "updates the description" do @@ -72,7 +73,7 @@ describe Api::V1::CakesController do expect(cake.story).to eql(new_story) end - it 'updates the category' do + it "updates the category" do category = create(:category) xhr :patch, :update, id: cake.id, cake: { category_id: category.id } diff --git a/spec/controllers/api/v1/photos_controller_spec.rb b/spec/controllers/api/v1/photos_controller_spec.rb index 35204e70..9ce72eaa 100644 --- a/spec/controllers/api/v1/photos_controller_spec.rb +++ b/spec/controllers/api/v1/photos_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" module Api module V1 @@ -9,11 +9,11 @@ module Api let!(:cake) { create(:creation, user: user) } before :each do - request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token) + api_login(user) end describe "#index" do - it 'loads the cakes photos' do + it "loads the cakes photos" do xhr :get, :index, cake_id: cake.id expect(assigns(:photos)).to match_array(cake.photos) end @@ -22,23 +22,23 @@ module Api describe "#show" do let(:photo) { create(:photo, imageable: cake) } - it 'loads the photo' do + it "loads the photo" do xhr :get, :show, cake_id: cake.id, id: photo.id expect(assigns(:photo)).to eql(photo) end end describe "#create" do - let(:file) { fixture_file_upload('images/example.png', 'image/png') } + let(:file) { fixture_file_upload("images/example.png", "image/png") } - it 'attaches a new photo to a cake' do + it "attaches a new photo to a cake" do allow(ProcessPhotoJob).to receive(:perform_later) - xhr :post, :create, cake_id: cake.id, watermark: 'watery', image: file + xhr :post, :create, cake_id: cake.id, watermark: "watery", image: file cake.reload expect(cake.photos.count).to eql(1) - expect(cake.photos.first.watermark).to eql('watery') + expect(cake.photos.first.watermark).to eql("watery") expect(cake.photos.first.image_processing).to be_truthy expect(ProcessPhotoJob).to have_received(:perform_later) end diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb index 3789694c..d4c02e4b 100644 --- a/spec/controllers/api/v1/profiles_controller_spec.rb +++ b/spec/controllers/api/v1/profiles_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" module Api module V1 @@ -7,40 +7,40 @@ module Api let(:user) { create(:user) } before :each do - request.env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token) + api_login(user) end describe "#show" do - it 'loads the current users profile' do - xhr :get, :show, id: 'me' + it "loads the current users profile" do + xhr :get, :show, id: "me" expect(assigns(:profile)).to eql(user) end end describe "#update" do - it 'updates the users profile' do + it "updates the users profile" do new_attributes = { - name: 'new name', - email: 'new@example.com', - city: 'new town', - website: 'http://example.com', - twitter: 'blabber', - facebook: 'facebookie', + name: "new name", + email: "new@example.com", + city: "new town", + website: "http://example.com", + twitter: "blabber", + facebook: "facebookie", } - xhr :patch, :update, id: 'me', profile: new_attributes + xhr :patch, :update, id: "me", profile: new_attributes user.reload - expect(user.name).to eql('new name') - expect(user.email).to eql('new@example.com') - expect(user.city).to eql('new town') - expect(user.website).to eql('http://example.com') - expect(user.twitter).to eql('blabber') - expect(user.facebook).to eql('facebookie') + expect(user.name).to eql("new name") + expect(user.email).to eql("new@example.com") + expect(user.city).to eql("new town") + expect(user.website).to eql("http://example.com") + expect(user.twitter).to eql("blabber") + expect(user.facebook).to eql("facebookie") end - it 'returns errors' do - xhr :patch, :update, id: 'me', profile: { email: '' } + it "returns errors" do + xhr :patch, :update, id: "me", profile: { email: "" } json = JSON.parse(response.body) expect(json["email"]).to_not be_empty end diff --git a/spec/controllers/api/v1/tutorials_controller_spec.rb b/spec/controllers/api/v1/tutorials_controller_spec.rb index 7d7ef5c6..704ce744 100644 --- a/spec/controllers/api/v1/tutorials_controller_spec.rb +++ b/spec/controllers/api/v1/tutorials_controller_spec.rb @@ -4,7 +4,7 @@ describe Api::V1::TutorialsController do let(:user) { create(:user) } before :each do - request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token) + api_login(user) end describe "#index" do @@ -22,9 +22,9 @@ describe Api::V1::TutorialsController do it "creates a new tutorial" do attributes = { url: "https://twitter.com/", - image_url: "https://abs.twimg.com/a/1405611403/img/t1/front_page/exp_wc2014_gen_laurenlemon.jpg", + image_url: "https://abs.twimg.com/a/img/t1/lemon.jpg", heading: "Twitter", - description: "Connect with your friends - and other fascinating people. Get in-the-moment updates on the things that interest you. And watch events unfold, in real time, from every angle.", + description: "Connect with your friends - and other fascinating people", tags: "cake,cookie", } xhr :post, :create, tutorial: attributes @@ -34,8 +34,8 @@ describe Api::V1::TutorialsController do expect(assigns(:tutorial).description).to eql(attributes[:description]) expect(assigns(:tutorial).heading).to eql(attributes[:heading]) expect(assigns(:tutorial).tags.count).to eql(2) - expect(assigns(:tutorial).tags.first.name).to eql('cake') - expect(assigns(:tutorial).tags.last.name).to eql('cookie') + expect(assigns(:tutorial).tags.first.name).to eql("cake") + expect(assigns(:tutorial).tags.last.name).to eql("cookie") end end end diff --git a/spec/controllers/api/v2/cakes_controller_spec.rb b/spec/controllers/api/v2/cakes_controller_spec.rb index 93ba4beb..dfba531c 100644 --- a/spec/controllers/api/v2/cakes_controller_spec.rb +++ b/spec/controllers/api/v2/cakes_controller_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" module Api module V2 @@ -6,32 +6,36 @@ module Api render_views describe "#index" do - let!(:cakes) { create(:category, slug: 'cakes') } - let!(:cookies) { create(:category, slug: 'cookies') } - let!(:cake) { create(:published_cake, name: 'cake', category: cakes) } - let!(:cookie) { create(:published_cake, name: 'cookie', category: cookies) } - let!(:unpublished_cake) { create(:cake, name: 'unpublished', category: cakes) } + let!(:cakes) { create(:category, slug: "cakes") } + let!(:cookies) { create(:category, slug: "cookies") } + let!(:cake) { create(:published_cake, name: "cake", category: cakes) } + let!(:cookie) do + create(:published_cake, name: "cookie", category: cookies) + end + let!(:unpublished_cake) do + create(:cake, name: "unpublished", category: cakes) + end - it 'returns all published cakes' do + it "returns all published cakes" do xhr :get, :index expect(assigns(:cakes)).to match_array([cake, cookie]) end - it 'returns all cakes in the category' do + it "returns all cakes in the category" do xhr :get, :index, category: cookie.category.slug expect(assigns(:cakes)).to match_array([cookie]) end - it 'returns all cakes matching the search query' do + it "returns all cakes matching the search query" do xhr :get, :index, q: cake.name[0..2] expect(assigns(:cakes)).to match_array([cake]) end - it 'returns all cakes tagged with the tag' do - cake.tag_list = 'cakes' + it "returns all cakes tagged with the tag" do + cake.tag_list = "cakes" cake.save! - xhr :get, :index, tags: 'cakes' + xhr :get, :index, tags: "cakes" expect(assigns(:cakes)).to match_array([cake]) end end @@ -39,7 +43,7 @@ module Api describe "#show" do let!(:cake) { create(:published_cake) } - it 'loads the cake' do + it "loads the cake" do xhr :get, :show, id: cake.id expect(assigns(:cake)).to eql(cake) end diff --git a/spec/controllers/api/v2/categories_controller_spec.rb b/spec/controllers/api/v2/categories_controller_spec.rb index 5a913145..3e5c4f65 100644 --- a/spec/controllers/api/v2/categories_controller_spec.rb +++ b/spec/controllers/api/v2/categories_controller_spec.rb @@ -1,12 +1,14 @@ -require 'rails_helper' +require "rails_helper" module Api module V2 describe CategoriesController do + render_views + describe "#index" do let!(:category) { create(:category) } - it 'loads all the categories' do + it "loads all the categories" do xhr :get, :index expect(assigns(:categories)).to match_array([category]) end @@ -16,7 +18,7 @@ module Api let!(:other_category) { create(:category) } let!(:category) { create(:category) } - it 'loads the specified category' do + it "loads the specified category" do xhr :get, :show, id: category.id expect(assigns(:category)).to eql(category) end diff --git a/spec/controllers/api/v2/photos_controller_spec.rb b/spec/controllers/api/v2/photos_controller_spec.rb index 0ed39995..09bdc736 100644 --- a/spec/controllers/api/v2/photos_controller_spec.rb +++ b/spec/controllers/api/v2/photos_controller_spec.rb @@ -1,13 +1,15 @@ -require 'rails_helper' +require "rails_helper" module Api module V2 describe PhotosController do + render_views + describe "#index" do let!(:processed_photo) { create(:photo, image_processing: nil) } let!(:unprocessed_photo) { create(:photo, image_processing: true) } - it 'loads all processed photos' do + it "loads all processed photos" do xhr :get, :index expect(assigns(:photos)).to match_array([processed_photo]) end @@ -17,7 +19,7 @@ module Api let!(:other_photo) { create(:photo) } let!(:photo) { create(:photo) } - it 'loads the specified photo' do + it "loads the specified photo" do xhr :get, :show, id: photo.id expect(assigns(:photo)).to eql(photo) end diff --git a/spec/controllers/api/v2/tutorials_controller_spec.rb b/spec/controllers/api/v2/tutorials_controller_spec.rb index c8d896ce..65954243 100644 --- a/spec/controllers/api/v2/tutorials_controller_spec.rb +++ b/spec/controllers/api/v2/tutorials_controller_spec.rb @@ -1,9 +1,10 @@ -require 'rails_helper' +require "rails_helper" module Api module V2 describe TutorialsController do render_views + describe "#index" do let!(:tutorial) { create(:tutorial) } @@ -11,26 +12,27 @@ module Api xhr :get, :index end - it 'loads all the tutorials' do + it "loads all the tutorials" do expect(assigns(:tutorials)).to match_array([tutorial]) end - it 'responds with json' do + it "responds with json" do json = JSON.parse(response.body) - expect(json['tutorials'].count).to eql(1) - expect(json['tutorials'][0]['id']).to eql(tutorial.id) - expect(json['tutorials'][0]['heading']).to eql(tutorial.heading) - expect(json['tutorials'][0]['description']).to eql(tutorial.description) - expect(json['tutorials'][0]['url']).to eql(tutorial.url) - expect(json['tutorials'][0]['submitter']).to eql(tutorial.user.id) - expect(json['tutorials'][0]['imageUrl']).to eql(tutorial.image_url) + expect(json["tutorials"].count).to eql(1) + json_tutorial = json["tutorials"][0] + expect(json_tutorial["id"]).to eql(tutorial.id) + expect(json_tutorial["heading"]).to eql(tutorial.heading) + expect(json_tutorial["description"]).to eql(tutorial.description) + expect(json_tutorial["url"]).to eql(tutorial.url) + expect(json_tutorial["submitter"]).to eql(tutorial.user.id) + expect(json_tutorial["imageUrl"]).to eql(tutorial.image_url) end end describe "#show" do let!(:tutorial) { create(:tutorial) } - it 'loads the single tutorial' do + it "loads the single tutorial" do xhr :get, :show, id: tutorial.id expect(assigns(:tutorial)).to eql(tutorial) end diff --git a/spec/controllers/api/v2/users_controller_spec.rb b/spec/controllers/api/v2/users_controller_spec.rb index 61368cd2..2400ede3 100644 --- a/spec/controllers/api/v2/users_controller_spec.rb +++ b/spec/controllers/api/v2/users_controller_spec.rb @@ -1,12 +1,14 @@ -require 'rails_helper' +require "rails_helper" module Api module V2 describe UsersController do + render_views + describe "#index" do let!(:user) { create(:user) } - it 'loads all users' do + it "loads all users" do xhr :get, :index expect(assigns(:users)).to match_array([user]) end @@ -15,7 +17,7 @@ module Api describe "#show" do let!(:user) { create(:user) } - it 'loads the info on the user' do + it "loads the info on the user" do xhr :get, :show, id: user.id expect(assigns(:user)).to eql(user) end |
