Skip to content

Commit

Permalink
Merge fb4dc6a into fc37fa2
Browse files Browse the repository at this point in the history
  • Loading branch information
npauzenga committed Jan 10, 2016
2 parents fc37fa2 + fb4dc6a commit cf2bbcf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
8 changes: 4 additions & 4 deletions spec/controllers/password_resets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

it "renders a success notice" do
post :create, params
expect(JSON.parse(response.body)).to eq(["reset sent"])
expect(json).to eq(["reset sent"])
end
end

Expand All @@ -40,7 +40,7 @@

it "renders an error" do
post :create, params
expect(JSON.parse(response.body)).to eq(["reset failed"])
expect(json).to eq(["reset failed"])
end
end
end
Expand Down Expand Up @@ -81,7 +81,7 @@

it "renders a success notice" do
patch :update, params
expect(JSON.parse(response.body)).to eq(["password updated"])
expect(json).to eq(["password updated"])
end
end

Expand All @@ -95,7 +95,7 @@

it "renders an error" do
patch :update, params
expect(JSON.parse(response.body)).to eq(["update failed"])
expect(json).to eq(["update failed"])
end
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
include Helpers

RSpec.describe UsersController do
let(:user) { create(:unconfirmed_user) }

Expand Down Expand Up @@ -73,7 +71,7 @@
it "returns an error" do
user.errors.add(:email, "error")
post :create, params
expect(JSON.parse(response.body)).to eq("email" => ["error"])
expect(json["email"]).to eq(["error"])
end
end
end
Expand Down Expand Up @@ -109,7 +107,7 @@

it "render the user as JSON" do
get :show, params
expect(response.body).to eq(user.to_json)
expect(serialize(user)).to eq(response.body)
end
end

Expand Down
3 changes: 3 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
config.include FactoryGirl::Syntax::Methods

# include custom helpers for authentication, json formatting, etc.
config.include RequestHelpers
end

require "simplecov"
Expand Down
6 changes: 0 additions & 6 deletions spec/support/helpers.rb

This file was deleted.

14 changes: 14 additions & 0 deletions spec/support/request_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module RequestHelpers
def json
JSON.parse(response.body)
end

def authenticate
token = Knock::AuthToken.new(payload: { sub: user.id }).token
request.env["HTTP_AUTHORIZATION"] = "bearer #{token}"
end

def serialize(resource)
ActiveModel::SerializableResource.new(resource).to_json
end
end

0 comments on commit cf2bbcf

Please sign in to comment.