summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2015-01-31 15:25:33 -0700
committermo khan <mo@mokhan.ca>2015-01-31 15:25:33 -0700
commit2a2da0f08f23401426674ba59cc36518beb27864 (patch)
treed4240819880b8911a2dead18c5fa0204f056638b /spec
parent52b41be14910a4e7f84e105e3a577dac1f988053 (diff)
parentc64e5008a494d1236e80df5583104bdc3b02bff4 (diff)
Merge branch 'master' of github.com:cakeside/cakeside into session-store
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/api/v1/cakes_controller_spec.rb98
-rw-r--r--spec/controllers/api/v1/categories_controller_spec.rb2
-rw-r--r--spec/controllers/api/v1/logins_controller_spec.rb11
-rw-r--r--spec/controllers/api/v1/photos_controller_spec.rb42
-rw-r--r--spec/controllers/api/v1/profiles_controller_spec.rb50
-rw-r--r--spec/controllers/api/v1/tutorials_controller_spec.rb17
-rw-r--r--spec/controllers/api/v2/cakes_controller_spec.rb30
-rw-r--r--spec/controllers/api/v2/categories_controller_spec.rb8
-rw-r--r--spec/controllers/api/v2/photos_controller_spec.rb8
-rw-r--r--spec/controllers/api/v2/tutorials_controller_spec.rb24
-rw-r--r--spec/controllers/api/v2/users_controller_spec.rb8
-rw-r--r--spec/controllers/cakes_controller_spec.rb37
-rw-r--r--spec/factories.rb2
-rw-r--r--spec/models/creation/repository_spec.rb29
-rw-r--r--spec/support/authentication.rb6
15 files changed, 288 insertions, 84 deletions
diff --git a/spec/controllers/api/v1/cakes_controller_spec.rb b/spec/controllers/api/v1/cakes_controller_spec.rb
index 00002975..7f84d3ae 100644
--- a/spec/controllers/api/v1/cakes_controller_spec.rb
+++ b/spec/controllers/api/v1/cakes_controller_spec.rb
@@ -1,23 +1,103 @@
require "rails_helper"
describe Api::V1::CakesController do
+ render_views
+
context "when signed in" do
let(:user) { create(:user) }
- let!(:my_cake) { create(:creation) }
- let!(:other_cake) { create(:creation) }
before :each do
- request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token)
- user.creations << my_cake
- get :index, :format => :json
+ api_login(user)
+ end
+
+ describe "#index" do
+ let!(:my_cake) { create(:creation) }
+ let!(:other_cake) { create(:creation) }
+
+ before :each do
+ user.creations << my_cake
+ xhr :get, :index
+ end
+
+ it "returns all of my cakes" do
+ expect(assigns(:cakes)).to match_array([my_cake])
+ end
+
+ it "does not return any other cakes" do
+ expect(assigns(:cakes)).to_not include(other_cake)
+ end
end
- it "should return all of my cakes" do
- expect(assigns(:cakes)).to match_array([my_cake])
+ describe "#show" do
+ let!(:cake) { create(:creation) }
+
+ before :each do
+ user.creations << cake
+ xhr :get, :show, id: cake.id
+ end
+
+ it "loads a specific cake" do
+ expect(assigns(:cake)).to eql(cake)
+ end
+ end
+
+ describe "#create" do
+ let(:category) { create(:category) }
+
+ it "creates a new project" do
+ xhr :post, :create, cake: { name: "new-cake", category_id: category.id }
+
+ expect(Creation.count).to eql(1)
+ expect(Creation.first.name).to eql("new-cake")
+ expect(Creation.first.category).to eql(category)
+ expect(Creation.first.user).to eql(user)
+ end
end
- it "should not return any other cakes" do
- expect(assigns(:cakes)).to_not include(other_cake)
+ describe "#update" do
+ let(:cake) { create(:cake, user: user) }
+
+ it "tags the cake" do
+ tags = ["cake", "cookies", "yummy"]
+ xhr :patch, :update, id: cake.id, cake: { tags: tags.join(", ") }
+
+ cake.reload
+ expect(cake.tags.pluck(:name)).to match_array(tags)
+ end
+
+ it "updates the description" do
+ new_story = "what is the haps on the craps"
+ xhr :patch, :update, id: cake.id, cake: { story: new_story }
+
+ cake.reload
+ expect(cake.story).to eql(new_story)
+ end
+
+ it "updates the category" do
+ category = create(:category)
+ xhr :patch, :update, id: cake.id, cake: { category_id: category.id }
+
+ cake.reload
+ expect(cake.category).to eql(category)
+ end
+ end
+
+ describe "#destroy" do
+ let!(:cake) { create(:creation) }
+
+ before :each do
+ user.creations << cake
+ xhr :delete, :destroy, id: cake.id
+ end
+
+ it "deletes the specified cake" do
+ expect(Creation.exists?(cake.id)).to be_falsey
+ end
+
+ it "returns an empty json response" do
+ json = JSON.parse(response.body)
+ expect(json["id"]).to eql(cake.id)
+ end
end
end
end
diff --git a/spec/controllers/api/v1/categories_controller_spec.rb b/spec/controllers/api/v1/categories_controller_spec.rb
index edd12d47..cf7cd3ba 100644
--- a/spec/controllers/api/v1/categories_controller_spec.rb
+++ b/spec/controllers/api/v1/categories_controller_spec.rb
@@ -3,6 +3,8 @@ require 'rails_helper'
module Api
module V1
describe CategoriesController do
+ render_views
+
describe "#index" do
it 'loads all the categories' do
xhr :get, :index
diff --git a/spec/controllers/api/v1/logins_controller_spec.rb b/spec/controllers/api/v1/logins_controller_spec.rb
index fedbf167..3b8d53e8 100644
--- a/spec/controllers/api/v1/logins_controller_spec.rb
+++ b/spec/controllers/api/v1/logins_controller_spec.rb
@@ -1,12 +1,15 @@
require "rails_helper"
describe Api::V1::LoginsController do
+ render_views
+
context "when logging in with proper credentials" do
let(:user) { create(:user) }
- it "should return the auth token" do
+ it "returns the auth token" do
post :create, { email: user.email, password: 'password' }
- expect(response.body).to eql({ auth_token: user.authentication_token }.to_json)
+ expected_json = { auth_token: user.authentication_token }.to_json
+ expect(response.body).to eql(expected_json)
end
end
@@ -15,8 +18,8 @@ describe Api::V1::LoginsController do
before { post :create, { email: user.email, password: user.password.reverse } }
- it "should return an empty auth token" do
- expect(response.body).to eql({ :auth_token => "" }.to_json)
+ it "returns an empty auth token" do
+ expect(response.body).to eql({ auth_token: "" }.to_json)
end
end
end
diff --git a/spec/controllers/api/v1/photos_controller_spec.rb b/spec/controllers/api/v1/photos_controller_spec.rb
index 49a8c218..9ce72eaa 100644
--- a/spec/controllers/api/v1/photos_controller_spec.rb
+++ b/spec/controllers/api/v1/photos_controller_spec.rb
@@ -1,22 +1,48 @@
-require 'rails_helper'
+require "rails_helper"
module Api
module V1
describe PhotosController do
+ render_views
+
let(:user) { create(:user) }
- let!(:cake) { create(:creation) }
+ let!(:cake) { create(:creation, user: user) }
- describe "#index" do
- before :each do
- request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token)
- user.creations << cake
- end
+ before :each do
+ api_login(user)
+ end
- it 'loads the cakes photos' do
+ describe "#index" do
+ it "loads the cakes photos" do
xhr :get, :index, cake_id: cake.id
expect(assigns(:photos)).to match_array(cake.photos)
end
end
+
+ describe "#show" do
+ let(:photo) { create(:photo, imageable: cake) }
+
+ 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") }
+
+ 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
+
+ cake.reload
+ expect(cake.photos.count).to eql(1)
+ 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
+ end
end
end
end
diff --git a/spec/controllers/api/v1/profiles_controller_spec.rb b/spec/controllers/api/v1/profiles_controller_spec.rb
new file mode 100644
index 00000000..d4c02e4b
--- /dev/null
+++ b/spec/controllers/api/v1/profiles_controller_spec.rb
@@ -0,0 +1,50 @@
+require "rails_helper"
+
+module Api
+ module V1
+ describe ProfilesController do
+ render_views
+ let(:user) { create(:user) }
+
+ before :each do
+ api_login(user)
+ end
+
+ describe "#show" do
+ 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
+ new_attributes = {
+ 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
+
+ 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")
+ end
+
+ it "returns errors" do
+ xhr :patch, :update, id: "me", profile: { email: "" }
+ json = JSON.parse(response.body)
+ expect(json["email"]).to_not be_empty
+ end
+ end
+ end
+ end
+end
diff --git a/spec/controllers/api/v1/tutorials_controller_spec.rb b/spec/controllers/api/v1/tutorials_controller_spec.rb
index 7d7ef5c6..d1e9a749 100644
--- a/spec/controllers/api/v1/tutorials_controller_spec.rb
+++ b/spec/controllers/api/v1/tutorials_controller_spec.rb
@@ -1,20 +1,20 @@
require "rails_helper"
describe Api::V1::TutorialsController do
+ render_views
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
- let(:my_tutorial) { create(:tutorial, user: user) }
- let(:other_tutorial) { create(:tutorial) }
+ let!(:my_tutorial) { create(:tutorial, user: user) }
+ let!(:other_tutorial) { create(:tutorial) }
it "returns the users tutorials" do
xhr :get, :index
- expect(assigns(:tutorials)).to include(my_tutorial)
- expect(assigns(:tutorials)).to_not include(other_tutorial)
+ expect(assigns(:tutorials)).to match_array([my_tutorial])
end
end
@@ -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,7 @@ 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.pluck(:name)).to match_array(["cake", "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
diff --git a/spec/controllers/cakes_controller_spec.rb b/spec/controllers/cakes_controller_spec.rb
index 209661c0..3d25f2ba 100644
--- a/spec/controllers/cakes_controller_spec.rb
+++ b/spec/controllers/cakes_controller_spec.rb
@@ -2,7 +2,6 @@ require 'rails_helper'
describe CakesController do
let(:user) { create(:user) }
- let(:cake) { create(:cake, user: user) }
before(:each) do
photo = 'spec/fixtures/images/example.png'
@@ -10,14 +9,44 @@ describe CakesController do
end
describe "#index" do
- before { get :index }
+ 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 "should display all creations" do
- expect(assigns(:creations)).to include(cake)
+ it "returns all published cakes" do
+ get :index
+ expect(assigns(:cakes)).to match_array([cake, cookie])
+ end
+
+ it "returns all cakes in the category" do
+ get :index, category: cookie.category.slug
+ expect(assigns(:cakes)).to match_array([cookie])
+ end
+
+ it "returns all cakes matching the search query" do
+ 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"
+ cake.save!
+
+ get :index, tags: "cakes"
+ expect(assigns(:cakes)).to match_array([cake])
end
end
describe "#show" do
+ let(:cake) { create(:cake, user: user) }
+
it "loads the cake" do
get :show, id: cake.id
expect(assigns(:creation)).to eql(cake)
diff --git a/spec/factories.rb b/spec/factories.rb
index 8cdc18f3..0b8f4773 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -6,7 +6,7 @@ FactoryGirl.define do
factory :category, class: Category do
name { Faker::Name.name }
- slug { Faker::Name.name.gsub(/ /, "-").downcase }
+ slug { Faker::Name.name.parameterize }
end
factory :cake, class: Creation, aliases: [:creation] do
diff --git a/spec/models/creation/repository_spec.rb b/spec/models/creation/repository_spec.rb
index 66d304d5..bd09b0fc 100644
--- a/spec/models/creation/repository_spec.rb
+++ b/spec/models/creation/repository_spec.rb
@@ -1,4 +1,4 @@
-require 'rails_helper'
+require "rails_helper"
describe Creation::Repository do
describe "#tagged" do
@@ -25,48 +25,45 @@ describe Creation::Repository do
let!(:published_cake){ create(:creation, user: user) }
before :each do
- published_cake.photos.create(image: 'example.png', image_processing: nil)
+ published_cake.photos.create(image: "example.png", image_processing: nil)
end
let(:results) { subject.published }
it "returns cakes that do not have photos that are processing" do
expect(results.count).to eql(1)
- expect(results).to include(published_cake)
+ expect(results).to match_array([published_cake])
end
end
describe "#search" do
- let(:cake) { create(:creation, name: 'Cake') }
- let(:cup_cake) { create(:creation, name: 'Cup Cake') }
+ let(:cake) { create(:creation, name: "Cake") }
+ let(:cup_cake) { create(:creation, name: "Cup Cake") }
it "returns cakes with a matching name" do
- results = subject.search('cake')
- expect(results).to include(cake)
- expect(results).to_not include(cup_cake)
+ expect(subject.search("cake")).to match_array([cake])
end
end
context "#search_with" do
let(:cake_category) { create(:category) }
- let!(:cake) { create(:cake, category: cake_category) }
- let!(:cookie) { create(:cake) }
+ let(:cookie_category) { create(:category) }
+ let!(:cake) { create(:cake, name: "cake", category: cake_category) }
+ let!(:cookie) { create(:cake, name: "cookie", category: cookie_category) }
before :each do
cake.photos << create(:photo)
cookie.photos << create(:photo)
end
- it 'returns all cakes in a specific category' do
+ it "returns all cakes in a specific category" do
cakes = subject.search_with(category: cake_category.slug)
- expect(cakes).to include(cake)
- expect(cakes).to_not include(cookie)
+ expect(cakes).to match_array([cake])
end
- it 'returns all cakes that match the search query' do
+ it "returns all cakes that match the search query" do
cakes = subject.search_with(q: cake.name[0..6])
- expect(cakes).to include(cake)
- expect(cakes).to_not include(cookie)
+ expect(cakes).to match_array([cake])
end
end
end
diff --git a/spec/support/authentication.rb b/spec/support/authentication.rb
index 194bd6ea..c56c027d 100644
--- a/spec/support/authentication.rb
+++ b/spec/support/authentication.rb
@@ -5,4 +5,10 @@ module Authentication
allow(controller).to receive(:current_user).and_return(user)
allow(controller).to receive(:user_signed_in?).and_return(true)
end
+
+ def api_login(user)
+ encoded_credentials = ActionController::HttpAuthentication::Token.
+ encode_credentials(user.authentication_token)
+ request.env["HTTP_AUTHORIZATION"] = encoded_credentials
+ end
end