-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
159 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
--color | ||
--require spec_helper | ||
--require rails_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Ability | ||
class ClientAbility | ||
include CanCan::Ability | ||
|
||
def initialize(client) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Ability | ||
class UserAbility | ||
include CanCan::Ability | ||
|
||
def initialize(user) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
describe TransactionsController, type: :api do | ||
before :each do | ||
@debtor = create :user | ||
@creditor = create :user | ||
@api_attributes = { | ||
debtor: @debtor.name, | ||
creditor: @creditor.name, | ||
message: Faker::Lorem.sentence, | ||
euros: 1, | ||
cents: 25 | ||
} | ||
end | ||
|
||
def post_transaction(extra_attributes = {}) | ||
post '/transactions', { transaction: @api_attributes.merge(extra_attributes) }, | ||
{ 'HTTP_ACCEPT' => "application/json", "X_API_KEY" => @key } | ||
end | ||
|
||
before :each do | ||
@client = Client.create name: "Tap" | ||
@key = @client.key | ||
end | ||
|
||
describe "Authentication" do | ||
it "should require a client authentication key" do | ||
post '/transactions' | ||
expect(last_response.status).to eq(401) | ||
end | ||
|
||
it "should work with valid key" do | ||
post_transaction | ||
expect(last_response.status).to eq(201) | ||
end | ||
end | ||
|
||
describe "successfull creating transaction" do | ||
it "should create a transaction" do | ||
expect { post_transaction }.to change { Transaction.count }.by(1) | ||
end | ||
|
||
it "should set issuer" do | ||
post_transaction | ||
@transaction = Transaction.last | ||
expect(@transaction.issuer).to eq(@client) | ||
end | ||
end | ||
|
||
describe "failed creating transaction" do | ||
it "should create a transaction" do | ||
expect { post_transaction(euros: -5) }.to change { Transaction.count }.by(0) | ||
end | ||
|
||
it "should give 402 status" do | ||
post_transaction(euros: -4) | ||
expect(last_response.status).to eq(422) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,36 @@ | ||
require 'rails_helper' | ||
describe UsersController, type: :controller do | ||
before :each do | ||
@user = create :penning | ||
sign_in @user | ||
end | ||
|
||
RSpec.describe UsersController, type: :controller do | ||
describe 'GET show' do | ||
before :each do | ||
get :show, id: @user | ||
end | ||
|
||
it 'should be successful' do | ||
expect(response).to render_template(:show) | ||
expect(response).to have_http_status(200) | ||
end | ||
|
||
it 'should load the correct user' do | ||
expect(assigns(:user)).to eq(@user) | ||
end | ||
end | ||
|
||
describe 'GET index' do | ||
before :each do | ||
get :index | ||
end | ||
|
||
it 'should load an array of all users' do | ||
expect(assigns(:users)).to eq([@user]) | ||
end | ||
|
||
it 'should render the correct template' do | ||
expect(response).to have_http_status(200) | ||
expect(response).to render_template(:index) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,2 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the TransactionsHelper. For example: | ||
# | ||
# describe TransactionsHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe TransactionsHelper, type: :helper do | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,2 @@ | ||
require 'rails_helper' | ||
|
||
# Specs in this file have access to a helper object that includes | ||
# the UsersHelper. For example: | ||
# | ||
# describe UsersHelper do | ||
# describe "string concat" do | ||
# it "concats two strings with spaces" do | ||
# expect(helper.concat_strings("this","that")).to eq("this that") | ||
# end | ||
# end | ||
# end | ||
RSpec.describe UsersHelper, type: :helper do | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module ApiHelper | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Rails.application | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include ApiHelper, type: :api #apply to all spec for apis folder | ||
end |