-
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.
Create routes for remaining relationships
Create tests for merchant/invoice relationship Create controller for merchants/invoices
- Loading branch information
Showing
6 changed files
with
65 additions
and
8 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 | ||
--format=documentation | ||
--require spec_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Api::V1::Merchants::InvoicesController < ApplicationController | ||
def index | ||
render json: Merchant.find(params[:merchant_id]).invoices | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
Rails.application.routes.draw do | ||
|
||
|
||
|
||
namespace :api do | ||
namespace :v1 do | ||
# resources :merchants, only: [:index] | ||
resources :merchants, only: [:index, :show] do | ||
scope module: "merchants" do | ||
resources :items, only: [:index] | ||
resources :invoices, only: [:index] | ||
end | ||
end | ||
resources :customers, only: [:index, :show] | ||
resources :invoices, only: [:index, :show] | ||
resources :items, only: [:index, :show] | ||
resources :invoice_items, only: [:index, :show] | ||
resources :transactions, only: [:index, :show] | ||
|
||
resources :customers, only: [:index, :show] do | ||
scope module: "customers" do | ||
resources :invoices, only: [:index] | ||
resources :transactions, only: [:index] | ||
end | ||
end | ||
|
||
resources :invoices, only: [:index, :show] do | ||
scope module: "invoices" do | ||
resources :transactions, only: [:index] | ||
resources :invoice_items, only: [:index] | ||
resources :items, only: [:index] | ||
resources :customers, only: [:index] | ||
resources :merchants, only: [:index] | ||
end | ||
end | ||
|
||
resources :items, only: [:index, :show] do | ||
scope module: "items" do | ||
resources :invoice_items, only: [:index] | ||
resources :merchants, only: [:index] | ||
end | ||
end | ||
|
||
resources :invoice_items, only: [:index, :show] do | ||
scope module: "invoice_items" do | ||
resources :invoices, only: [:index] | ||
resources :items, only: [:index] | ||
end | ||
end | ||
|
||
resources :transactions, only: [:index, :show] do | ||
scope module: "transactions" do | ||
resources :invoices, only: [:index] | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
factory :merchant do | ||
name "Merchant Name" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rails_helper' | ||
|
||
describe "merchant/invoices relationship endpoints" do | ||
context "get /api/v1/merchants/:merchant_id/invoices" do | ||
it "returns a collection of invoices associated with that merchant" do | ||
merchant = create(:merchant) | ||
merchant_2 = create(:merchant) | ||
create_list(:invoice, 3, merchant_id: merchant.id) | ||
create(:invoice, merchant_id: merchant_2.id) | ||
|
||
get "/api/v1/merchants/#{merchant.id}/invoices" | ||
|
||
|
||
invoices = JSON.parse(response.body) | ||
|
||
expect(response).to be_success | ||
expect(invoices.count).to eq(3) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,5 @@ | |
expect(merchant["id"]).to eq(id) | ||
end | ||
end | ||
|
||
end |