From 50129fc5d5da4d38a243f0484fe55453aee416a6 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 10:26:57 -0700 Subject: [PATCH 01/18] Adds service --- Gemfile | 1 + Gemfile.lock | 5 ++++- app/services/rails_engine_service.rb | 3 +++ spec/features/merchants/merchants_index_spec.rb | 12 ++++++++++++ spec/services/rails_engine_service_spec.rb | 9 +++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/services/rails_engine_service.rb create mode 100644 spec/features/merchants/merchants_index_spec.rb create mode 100644 spec/services/rails_engine_service_spec.rb diff --git a/Gemfile b/Gemfile index d4fbf7c0..ef3e6e51 100644 --- a/Gemfile +++ b/Gemfile @@ -42,6 +42,7 @@ group :development, :test do gem 'rspec-rails' gem 'capybara' gem 'pry' + gem 'faraday' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 9c8920e9..7dda771a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -97,6 +97,8 @@ GEM nio4r (2.5.8) nokogiri (1.12.5-arm64-darwin) racc (~> 1.4) + nokogiri (1.12.5-x86_64-darwin) + racc (~> 1.4) pg (1.2.3) pry (0.14.1) coderay (~> 1.1) @@ -199,6 +201,7 @@ GEM PLATFORMS arm64-darwin-20 + x86_64-darwin-21 DEPENDENCIES bootsnap (>= 1.1.0) @@ -224,4 +227,4 @@ RUBY VERSION ruby 2.7.4p191 BUNDLED WITH - 2.2.27 + 2.4.4 diff --git a/app/services/rails_engine_service.rb b/app/services/rails_engine_service.rb new file mode 100644 index 00000000..f0beeacd --- /dev/null +++ b/app/services/rails_engine_service.rb @@ -0,0 +1,3 @@ +class RailsEngineService + +end \ No newline at end of file diff --git a/spec/features/merchants/merchants_index_spec.rb b/spec/features/merchants/merchants_index_spec.rb new file mode 100644 index 00000000..30776bda --- /dev/null +++ b/spec/features/merchants/merchants_index_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +RSpec.describe 'merchants index', type: :feature do + describe 'visiting /merchants' do + it 'see list of merchants by name' do + + end + + it 'when a merchants name is clicked the user should be directed to /merchants/:id + and they should see a list of items that merchant sells' + end +end \ No newline at end of file diff --git a/spec/services/rails_engine_service_spec.rb b/spec/services/rails_engine_service_spec.rb new file mode 100644 index 00000000..9ff8fce2 --- /dev/null +++ b/spec/services/rails_engine_service_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +RSpec.describe RailsEngineService do + describe 'get_all_merchants' do + it 'can return a list of merchants' do + + end + end +end \ No newline at end of file From 8f9ecf4aaa05a5298c798a5ed23551e9905f2bff Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 11:21:56 -0700 Subject: [PATCH 02/18] Adds get_all_merchants --- Gemfile | 4 ++-- Gemfile.lock | 12 ++++++++++-- app/services/rails_engine_service.rb | 9 ++++++++- spec/services/rails_engine_service_spec.rb | 13 +++++++++++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index ef3e6e51..99f5b024 100644 --- a/Gemfile +++ b/Gemfile @@ -35,14 +35,14 @@ gem 'jbuilder', '~> 2.5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false +gem 'faraday' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'rspec-rails' gem 'capybara' - gem 'pry' - gem 'faraday' + gem 'pry-rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 7dda771a..b0f1fc4b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -72,6 +72,10 @@ GEM diff-lcs (1.4.4) erubi (1.10.0) execjs (2.8.1) + faraday (2.7.4) + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-net_http (3.0.2) ffi (1.15.4) globalid (0.5.2) activesupport (>= 5.0) @@ -100,9 +104,11 @@ GEM nokogiri (1.12.5-x86_64-darwin) racc (~> 1.4) pg (1.2.3) - pry (0.14.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) + pry-rails (0.3.9) + pry (>= 0.10.4) public_suffix (4.0.6) puma (3.12.6) racc (1.6.0) @@ -155,6 +161,7 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.10.2) + ruby2_keywords (0.0.5) ruby_dep (1.5.0) sass (3.7.4) sass-listen (~> 4.0.0) @@ -208,10 +215,11 @@ DEPENDENCIES byebug capybara coffee-rails (~> 4.2) + faraday jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) - pry + pry-rails puma (~> 3.11) rails (~> 5.2.6) rspec-rails diff --git a/app/services/rails_engine_service.rb b/app/services/rails_engine_service.rb index f0beeacd..965f3915 100644 --- a/app/services/rails_engine_service.rb +++ b/app/services/rails_engine_service.rb @@ -1,3 +1,10 @@ class RailsEngineService - + def self.conn + Faraday.new('http://localhost:3000/api/v1/') + end + + def self.get_all_merchants + response = conn.get('merchants') + JSON.parse(response.body, symbolize_names: true) + end end \ No newline at end of file diff --git a/spec/services/rails_engine_service_spec.rb b/spec/services/rails_engine_service_spec.rb index 9ff8fce2..5ddda554 100644 --- a/spec/services/rails_engine_service_spec.rb +++ b/spec/services/rails_engine_service_spec.rb @@ -1,9 +1,18 @@ -require 'spec_helper' +require 'rails_helper' RSpec.describe RailsEngineService do describe 'get_all_merchants' do it 'can return a list of merchants' do - + response = RailsEngineService.get_all_merchants + + expect(response).to have_key(:data) + expect(response[:data]).to be_a(Array) + + response[:data].each do |data| + expect(data).to have_key(:id) + expect(data).to have_key(:attributes) + expect(data[:attributes]).to have_key(:name) + end end end end \ No newline at end of file From c462a811bf210b2693490e36638778600dbb91f3 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 11:44:32 -0700 Subject: [PATCH 03/18] Adds Merchant facade and #self.all_merchants --- app/facades/merchant_facade.rb | 11 +++++++++++ app/services/rails_engine_service.rb | 6 +++++- spec/facades/merchant_facade_spec.rb | 16 ++++++++++++++++ spec/features/merchants/merchants_index_spec.rb | 7 +++++-- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 app/facades/merchant_facade.rb create mode 100644 spec/facades/merchant_facade_spec.rb diff --git a/app/facades/merchant_facade.rb b/app/facades/merchant_facade.rb new file mode 100644 index 00000000..035697c4 --- /dev/null +++ b/app/facades/merchant_facade.rb @@ -0,0 +1,11 @@ +class MerchantFacade + def sell.all_merchants + response = RailsEngineService.get_all_merchants + + merchants = response[:data] + + merchants = data.map do |merchant| + Merchant.new(merchant) + end + end +end \ No newline at end of file diff --git a/app/services/rails_engine_service.rb b/app/services/rails_engine_service.rb index 965f3915..2878b95a 100644 --- a/app/services/rails_engine_service.rb +++ b/app/services/rails_engine_service.rb @@ -3,8 +3,12 @@ def self.conn Faraday.new('http://localhost:3000/api/v1/') end + def self.json_parse(response) + JSON.parse(response.body, symbolize_names: true) + end + def self.get_all_merchants response = conn.get('merchants') - JSON.parse(response.body, symbolize_names: true) + json_parse(response) end end \ No newline at end of file diff --git a/spec/facades/merchant_facade_spec.rb b/spec/facades/merchant_facade_spec.rb new file mode 100644 index 00000000..eadb8ecb --- /dev/null +++ b/spec/facades/merchant_facade_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe MerchantFacade do + describe 'merchant calls' do + it 'all_merchants' do + merchants = MerchantFacade.all_merchants + + expect(merchants).to be_a(Array) + + merchants.each do |merchant| + expect(merchant).to be_instance_of(Merchant) + end + expect(merchants[0].name).to eq("Schroeder-Jerde") + end + end +end \ No newline at end of file diff --git a/spec/features/merchants/merchants_index_spec.rb b/spec/features/merchants/merchants_index_spec.rb index 30776bda..4db78f13 100644 --- a/spec/features/merchants/merchants_index_spec.rb +++ b/spec/features/merchants/merchants_index_spec.rb @@ -1,9 +1,12 @@ -require 'spec_helper' +require 'rails_helper' RSpec.describe 'merchants index', type: :feature do - describe 'visiting /merchants' do + xdescribe 'visiting /merchants' do it 'see list of merchants by name' do + visit '/merchants' + expect(page).to have_content(Merchant.first.name) + expect(page).to have_content(Merchant.second.name) end it 'when a merchants name is clicked the user should be directed to /merchants/:id From 12e403470d4e31eb72cc37ddaa57f1f9970597a1 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 12:00:50 -0700 Subject: [PATCH 04/18] Adds merchant poro --- app/facades/merchant_facade.rb | 9 ++++----- app/poros/merchant.rb | 9 +++++++++ spec/facades/merchant_facade_spec.rb | 1 + spec/poros/merchant_spec.rb | 11 +++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 app/poros/merchant.rb create mode 100644 spec/poros/merchant_spec.rb diff --git a/app/facades/merchant_facade.rb b/app/facades/merchant_facade.rb index 035697c4..082f64d1 100644 --- a/app/facades/merchant_facade.rb +++ b/app/facades/merchant_facade.rb @@ -1,11 +1,10 @@ class MerchantFacade - def sell.all_merchants + def self.all_merchants response = RailsEngineService.get_all_merchants - merchants = response[:data] - - merchants = data.map do |merchant| - Merchant.new(merchant) + + merchants.map do |data| + Merchant.new(data) end end end \ No newline at end of file diff --git a/app/poros/merchant.rb b/app/poros/merchant.rb new file mode 100644 index 00000000..6d47b8d7 --- /dev/null +++ b/app/poros/merchant.rb @@ -0,0 +1,9 @@ +class Merchant + attr_reader :name, + :id + def initialize(data) + @name = data[:attributes][:name] + # binding.pry + @id = data[:id] + end +end \ No newline at end of file diff --git a/spec/facades/merchant_facade_spec.rb b/spec/facades/merchant_facade_spec.rb index eadb8ecb..f8198b9b 100644 --- a/spec/facades/merchant_facade_spec.rb +++ b/spec/facades/merchant_facade_spec.rb @@ -11,6 +11,7 @@ expect(merchant).to be_instance_of(Merchant) end expect(merchants[0].name).to eq("Schroeder-Jerde") + expect(merchants[1].name).to eq("Klein, Rempel and Jones") end end end \ No newline at end of file diff --git a/spec/poros/merchant_spec.rb b/spec/poros/merchant_spec.rb new file mode 100644 index 00000000..9058f0a0 --- /dev/null +++ b/spec/poros/merchant_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe Merchant do + it 'merchant exists and has attributes' do + data = {id: 1, attributes: {name: "Albatross Smith"}} + merchant1 = Merchant.new(data) + + expect(merchant1.name).to eq("Albatross Smith") + expect(merchant1.id).to eq(1) + end +end \ No newline at end of file From c0d17d2af9b3b6aff651c100112572ca82db866f Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 19:55:13 -0700 Subject: [PATCH 05/18] Adds /merchants view and lists all merchants there --- app/controllers/merchants_controller.rb | 5 +++++ app/views/merchants/index.html.erb | 7 +++++++ config/routes.rb | 2 ++ spec/features/merchants/merchants_index_spec.rb | 8 +++++--- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 app/controllers/merchants_controller.rb create mode 100644 app/views/merchants/index.html.erb diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb new file mode 100644 index 00000000..e04cbb5f --- /dev/null +++ b/app/controllers/merchants_controller.rb @@ -0,0 +1,5 @@ +class MerchantsController < ApplicationController + def index + @merchants = MerchantFacade.all_merchants + end +end \ No newline at end of file diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb new file mode 100644 index 00000000..eca56966 --- /dev/null +++ b/app/views/merchants/index.html.erb @@ -0,0 +1,7 @@ +

Merchants

+ +
+ <% @merchants. each do |merchant| %> + <%= merchant.name %> + <% end %> +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 787824f8..6e3f0da1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + + resources :merchants, only:[:index] end diff --git a/spec/features/merchants/merchants_index_spec.rb b/spec/features/merchants/merchants_index_spec.rb index 4db78f13..00e6ac33 100644 --- a/spec/features/merchants/merchants_index_spec.rb +++ b/spec/features/merchants/merchants_index_spec.rb @@ -1,12 +1,14 @@ require 'rails_helper' RSpec.describe 'merchants index', type: :feature do - xdescribe 'visiting /merchants' do + describe 'visiting /merchants' do it 'see list of merchants by name' do visit '/merchants' - expect(page).to have_content(Merchant.first.name) - expect(page).to have_content(Merchant.second.name) + within "#merchants" do + expect(page).to have_content("Schroeder-Jerde") + expect(page).to have_content("Klein, Rempel and Jones") + end end it 'when a merchants name is clicked the user should be directed to /merchants/:id From 607ce7c761587c48419794b80f31c83fa1a43771 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 20:20:23 -0700 Subject: [PATCH 06/18] Adds #self.get_one_merchant to railsengineservice and #self.one_merchant to MerchantFacade --- app/controllers/merchants_controller.rb | 4 ++++ app/facades/merchant_facade.rb | 5 +++++ app/services/rails_engine_service.rb | 5 +++++ app/views/merchants/index.html.erb | 2 +- app/views/merchants/show.html.erb | 0 config/routes.rb | 2 +- spec/facades/merchant_facade_spec.rb | 8 ++++++++ spec/features/merchants/merchants_index_spec.rb | 13 ++++++++++++- spec/services/rails_engine_service_spec.rb | 14 ++++++++++++++ 9 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 app/views/merchants/show.html.erb diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index e04cbb5f..62b3fa05 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -2,4 +2,8 @@ class MerchantsController < ApplicationController def index @merchants = MerchantFacade.all_merchants end + + def show + # binding.pry + end end \ No newline at end of file diff --git a/app/facades/merchant_facade.rb b/app/facades/merchant_facade.rb index 082f64d1..208ac4b4 100644 --- a/app/facades/merchant_facade.rb +++ b/app/facades/merchant_facade.rb @@ -7,4 +7,9 @@ def self.all_merchants Merchant.new(data) end end + + def self.one_merchant + response = RailsEngineService.get_one_merchant(merchant_id) + Merchant.new(response[:data]) + end end \ No newline at end of file diff --git a/app/services/rails_engine_service.rb b/app/services/rails_engine_service.rb index 2878b95a..e416edfb 100644 --- a/app/services/rails_engine_service.rb +++ b/app/services/rails_engine_service.rb @@ -11,4 +11,9 @@ def self.get_all_merchants response = conn.get('merchants') json_parse(response) end + + def self.get_one_merchant(merchant_id) + response = conn.get("merchants/#{merchant_id}") + json_parse(response) + end end \ No newline at end of file diff --git a/app/views/merchants/index.html.erb b/app/views/merchants/index.html.erb index eca56966..834f597f 100644 --- a/app/views/merchants/index.html.erb +++ b/app/views/merchants/index.html.erb @@ -2,6 +2,6 @@
<% @merchants. each do |merchant| %> - <%= merchant.name %> +

<%= link_to merchant.name, "/merchants/#{merchant.id}" %>


<% end %>
\ No newline at end of file diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/config/routes.rb b/config/routes.rb index 6e3f0da1..a853a5d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html - resources :merchants, only:[:index] + resources :merchants, only:[:index, :show] end diff --git a/spec/facades/merchant_facade_spec.rb b/spec/facades/merchant_facade_spec.rb index f8198b9b..15c6f16b 100644 --- a/spec/facades/merchant_facade_spec.rb +++ b/spec/facades/merchant_facade_spec.rb @@ -13,5 +13,13 @@ expect(merchants[0].name).to eq("Schroeder-Jerde") expect(merchants[1].name).to eq("Klein, Rempel and Jones") end + + it 'one_merchant' do + merchant = MerchantFacade.one_merchant(42) + + expect(merchant).to be_instance_of(Merchant) + expect(merchant.id).to eq(42) + expect(merchant.name).to eq("Glover Inc") + end end end \ No newline at end of file diff --git a/spec/features/merchants/merchants_index_spec.rb b/spec/features/merchants/merchants_index_spec.rb index 00e6ac33..1f8175a0 100644 --- a/spec/features/merchants/merchants_index_spec.rb +++ b/spec/features/merchants/merchants_index_spec.rb @@ -12,6 +12,17 @@ end it 'when a merchants name is clicked the user should be directed to /merchants/:id - and they should see a list of items that merchant sells' + and they should see a list of items that merchant sells' do + visit '/merchants' + + click_link 'Schroeder-Jerde' + + expect(current_path).to eq('/merchants/1') + expect(page).to have_content("Item Nemo Facere") + expect(page).to have_content("Item Expedita Aliquam") + expect(page).to have_content("Item Provident At") + expect(page).to have_content("Item Expedita Fuga") + expect(page).to have_content("Item Est Consequuntur") + end end end \ No newline at end of file diff --git a/spec/services/rails_engine_service_spec.rb b/spec/services/rails_engine_service_spec.rb index 5ddda554..123282ce 100644 --- a/spec/services/rails_engine_service_spec.rb +++ b/spec/services/rails_engine_service_spec.rb @@ -15,4 +15,18 @@ end end end + + describe 'get_one_merchant' do + it 'can return one merchant response' do + response = RailsEngineService.get_one_merchant(42) + + expect(response).to have_key(:data) + expect(response[:data]).to be_a(Hash) + expect(response[:data]).to have_key(:id) + expect(response[:data][:attributes]).to have_key(:name) + + expect(response[:data][:id]).to eq("42") + expect(response[:data][:attributes][:name]).to eq("Glover Inc") + end + end end \ No newline at end of file From c957e4d3affda1e8aa0b03498ee579567c511f76 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 20:36:03 -0700 Subject: [PATCH 07/18] Adds #self.get_one_merchants_items to RailsEngineService --- app/controllers/merchants_controller.rb | 1 + app/facades/merchant_facade.rb | 2 +- app/services/rails_engine_service.rb | 5 +++++ app/views/merchants/show.html.erb | 5 +++++ spec/facades/merchant_facade_spec.rb | 2 +- .../merchants/merchants_index_spec.rb | 14 ++++++++----- spec/services/rails_engine_service_spec.rb | 20 +++++++++++++++++++ 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index 62b3fa05..a58cf055 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -4,6 +4,7 @@ def index end def show + @merchant = MerchantFacade.one_merchant(params[:id]) # binding.pry end end \ No newline at end of file diff --git a/app/facades/merchant_facade.rb b/app/facades/merchant_facade.rb index 208ac4b4..51375500 100644 --- a/app/facades/merchant_facade.rb +++ b/app/facades/merchant_facade.rb @@ -8,7 +8,7 @@ def self.all_merchants end end - def self.one_merchant + def self.one_merchant(merchant_id) response = RailsEngineService.get_one_merchant(merchant_id) Merchant.new(response[:data]) end diff --git a/app/services/rails_engine_service.rb b/app/services/rails_engine_service.rb index e416edfb..b865845f 100644 --- a/app/services/rails_engine_service.rb +++ b/app/services/rails_engine_service.rb @@ -16,4 +16,9 @@ def self.get_one_merchant(merchant_id) response = conn.get("merchants/#{merchant_id}") json_parse(response) end + + def self.get_one_merchants_items(merchant_id) + response = conn.get("merchants/#{merchant_id}/items") + json_parse(response) + end end \ No newline at end of file diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index e69de29b..bb407292 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -0,0 +1,5 @@ +

<%= @merchant.name %>'s Items

+ +
+ +
\ No newline at end of file diff --git a/spec/facades/merchant_facade_spec.rb b/spec/facades/merchant_facade_spec.rb index 15c6f16b..ab45841a 100644 --- a/spec/facades/merchant_facade_spec.rb +++ b/spec/facades/merchant_facade_spec.rb @@ -18,7 +18,7 @@ merchant = MerchantFacade.one_merchant(42) expect(merchant).to be_instance_of(Merchant) - expect(merchant.id).to eq(42) + expect(merchant.id).to eq("42") expect(merchant.name).to eq("Glover Inc") end end diff --git a/spec/features/merchants/merchants_index_spec.rb b/spec/features/merchants/merchants_index_spec.rb index 1f8175a0..2be32f64 100644 --- a/spec/features/merchants/merchants_index_spec.rb +++ b/spec/features/merchants/merchants_index_spec.rb @@ -18,11 +18,15 @@ click_link 'Schroeder-Jerde' expect(current_path).to eq('/merchants/1') - expect(page).to have_content("Item Nemo Facere") - expect(page).to have_content("Item Expedita Aliquam") - expect(page).to have_content("Item Provident At") - expect(page).to have_content("Item Expedita Fuga") - expect(page).to have_content("Item Est Consequuntur") + expect(page).to have_content("Schroeder-Jerde's Items") + + within "#items" do + expect(page).to have_content("Item Nemo Facere") + expect(page).to have_content("Item Expedita Aliquam") + expect(page).to have_content("Item Provident At") + expect(page).to have_content("Item Expedita Fuga") + expect(page).to have_content("Item Est Consequuntur") + end end end end \ No newline at end of file diff --git a/spec/services/rails_engine_service_spec.rb b/spec/services/rails_engine_service_spec.rb index 123282ce..f5fb92ab 100644 --- a/spec/services/rails_engine_service_spec.rb +++ b/spec/services/rails_engine_service_spec.rb @@ -29,4 +29,24 @@ expect(response[:data][:attributes][:name]).to eq("Glover Inc") end end + + describe 'get_one_merchants_items' do + it 'can return all the items for an individual merchant' do + response = RailsEngineService.get_one_merchants_items(99) + + expect(response).to have_key(:data) + expect(response[:data]).to be_a(Array) + + response[:data].each do |item| + expect(item).to have_key(:id) + expect(item[:attributes]).to have_key(:name) + expect(item[:attributes]).to have_key(:description) + expect(item[:attributes]).to have_key(:unit_price) + expect(item[:attributes]).to have_key(:merchant_id) + end + + expect(response[:data][0][:attributes][:name]).to eq("Item Excepturi Rem") + expect(response[:data][0][:attributes][:merchant_id]).to eq(99) + end + end end \ No newline at end of file From 35af1ab86247c572f05dcd0d09fbb21317276d77 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 20:41:13 -0700 Subject: [PATCH 08/18] Adds #self.one_merchants_items to MerchantFacade --- app/facades/merchant_facade.rb | 9 +++++++++ spec/facades/merchant_facade_spec.rb | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/facades/merchant_facade.rb b/app/facades/merchant_facade.rb index 51375500..e4ec420e 100644 --- a/app/facades/merchant_facade.rb +++ b/app/facades/merchant_facade.rb @@ -12,4 +12,13 @@ def self.one_merchant(merchant_id) response = RailsEngineService.get_one_merchant(merchant_id) Merchant.new(response[:data]) end + + def self.one_merchants_items(merchant_id) + response = RailsEngineService.get_one_merchants_items(merchant_id) + items = response[:data] + + items.map do |data| + Item.new(data) + end + end end \ No newline at end of file diff --git a/spec/facades/merchant_facade_spec.rb b/spec/facades/merchant_facade_spec.rb index ab45841a..00a24a16 100644 --- a/spec/facades/merchant_facade_spec.rb +++ b/spec/facades/merchant_facade_spec.rb @@ -21,5 +21,20 @@ expect(merchant.id).to eq("42") expect(merchant.name).to eq("Glover Inc") end + + it "one_merchants_items" do + items = MerchantFacade.one_merchants_items(99) + + expect(items).to be_a(Array) + + items.each do |item| + expect(item).to be_instance_of(Item) + end + + expect(items[0].name).to eq("Item Excepturi Rem") + expect(items[0].description).to eq("Perferendis reprehenderit fugiat sit eos. Corporis ipsum ut. Natus molestiae quia rerum fugit quis. A cumque doloremque magni.") + expect(items[0].unit_price).to eq(476.82) + expect(items[0].merchant_id).to eq(99) + end end end \ No newline at end of file From 8b03d2ce0955e6ddb2555c415ea5de7714899fbf Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 20:49:42 -0700 Subject: [PATCH 09/18] Adds Item.rb --- app/poros/item.rb | 12 ++++++++++++ spec/poros/item_spec.rb | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 app/poros/item.rb create mode 100644 spec/poros/item_spec.rb diff --git a/app/poros/item.rb b/app/poros/item.rb new file mode 100644 index 00000000..b0c079f5 --- /dev/null +++ b/app/poros/item.rb @@ -0,0 +1,12 @@ +class Item + attr_reader :id, + :name, + :description, + :unit_price + def initialize(data) + @id = data[:id] + @name = data[:attributes][:name] + @description = data[:attributes][:description] + @unit_price = data[:attributes][:unit_price] + end +end \ No newline at end of file diff --git a/spec/poros/item_spec.rb b/spec/poros/item_spec.rb new file mode 100644 index 00000000..663d3ec2 --- /dev/null +++ b/spec/poros/item_spec.rb @@ -0,0 +1,16 @@ +require 'rails_helper' + +RSpec.describe Item do + it 'item exists and has attribsutes' do + data = {id: "2425", attributes: {name: "Item Excepture Rem", + description: "Perferendis reprehenderit fugiat sit eos. Corporis ipsum ut. Natus molestiae quia rerum fugit quis. A cumque doloremque magni.", + unit_price: 476.82} + } + item1 = Item.new(data) + + expect(item1).to be_instance_of(Item) + expect(item1.name).to eq("Item Excepture Rem") + expect(item1.description).to eq("Perferendis reprehenderit fugiat sit eos. Corporis ipsum ut. Natus molestiae quia rerum fugit quis. A cumque doloremque magni.") + expect(item1.unit_price).to eq(476.82) + end +end \ No newline at end of file From 56c323fa19a2be69bc17f25b301baf1bbc6be723 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Wed, 15 Feb 2023 20:52:00 -0700 Subject: [PATCH 10/18] Adds items to a merchants show page --- app/controllers/merchants_controller.rb | 2 +- app/views/merchants/show.html.erb | 4 +++- spec/facades/merchant_facade_spec.rb | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/merchants_controller.rb b/app/controllers/merchants_controller.rb index a58cf055..4038f2fe 100644 --- a/app/controllers/merchants_controller.rb +++ b/app/controllers/merchants_controller.rb @@ -5,6 +5,6 @@ def index def show @merchant = MerchantFacade.one_merchant(params[:id]) - # binding.pry + @items = MerchantFacade.one_merchants_items(params[:id]) end end \ No newline at end of file diff --git a/app/views/merchants/show.html.erb b/app/views/merchants/show.html.erb index bb407292..2db9f7f4 100644 --- a/app/views/merchants/show.html.erb +++ b/app/views/merchants/show.html.erb @@ -1,5 +1,7 @@

<%= @merchant.name %>'s Items

- + <% @items.each do |item| %> +

<%= item.name %>

+ <% end %>
\ No newline at end of file diff --git a/spec/facades/merchant_facade_spec.rb b/spec/facades/merchant_facade_spec.rb index 00a24a16..f56240e1 100644 --- a/spec/facades/merchant_facade_spec.rb +++ b/spec/facades/merchant_facade_spec.rb @@ -34,7 +34,6 @@ expect(items[0].name).to eq("Item Excepturi Rem") expect(items[0].description).to eq("Perferendis reprehenderit fugiat sit eos. Corporis ipsum ut. Natus molestiae quia rerum fugit quis. A cumque doloremque magni.") expect(items[0].unit_price).to eq(476.82) - expect(items[0].merchant_id).to eq(99) end end end \ No newline at end of file From b3249896e693a9efdbdb1c68711c039866562417 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:27:46 -0700 Subject: [PATCH 11/18] Adds #self.get_all_items to service --- app/services/rails_engine_service.rb | 5 +++++ spec/features/items/items_index_spec.rb | 18 ++++++++++++++++++ spec/services/rails_engine_service_spec.rb | 17 +++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 spec/features/items/items_index_spec.rb diff --git a/app/services/rails_engine_service.rb b/app/services/rails_engine_service.rb index b865845f..85f9bee0 100644 --- a/app/services/rails_engine_service.rb +++ b/app/services/rails_engine_service.rb @@ -21,4 +21,9 @@ def self.get_one_merchants_items(merchant_id) response = conn.get("merchants/#{merchant_id}/items") json_parse(response) end + + def self.get_all_items + response = conn.get('items') + json_parse(response) + end end \ No newline at end of file diff --git a/spec/features/items/items_index_spec.rb b/spec/features/items/items_index_spec.rb new file mode 100644 index 00000000..b57a3acb --- /dev/null +++ b/spec/features/items/items_index_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe 'items index', type: :feature do + describe 'visiting /items' do + it 'see list of items by name' do + visit '/items' + + expect(page).to have_content("Item Nemo Facere") + expect(page).to have_content("Item Expedita Aliquam") + expect(page).to have_content("Item Provident At") + expect(page).to have_content("Item Expedita Fuga") + expect(page).to have_content("Item Est Consequuntur") + expect(page).to have_content("Item Quo Magnam") + expect(page).to have_content("Item Quidem Suscipit") + expect(page).to have_content("Item Rerum Magni") + end + end +end diff --git a/spec/services/rails_engine_service_spec.rb b/spec/services/rails_engine_service_spec.rb index f5fb92ab..b2f83fee 100644 --- a/spec/services/rails_engine_service_spec.rb +++ b/spec/services/rails_engine_service_spec.rb @@ -49,4 +49,21 @@ expect(response[:data][0][:attributes][:merchant_id]).to eq(99) end end + + describe 'get_all_items' do + it 'returns all items' do + response = RailsEngineService.get_all_items + + expect(response).to have_key(:data) + expect(response[:data]).to be_a(Array) + + response[:data].each do |item| + expect(item).to have_key(:id) + expect(item[:attributes]).to have_key(:name) + expect(item[:attributes]).to have_key(:description) + expect(item[:attributes]).to have_key(:unit_price) + expect(item[:attributes]).to have_key(:merchant_id) + end + end + end end \ No newline at end of file From 7d565d99b1156aaf66714941efe0066975bab13a Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:34:12 -0700 Subject: [PATCH 12/18] Adds ItemFacade with #self.all_items --- app/facades/item_facade.rb | 10 ++++++++++ spec/facades/item_facade_spec.rb | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/facades/item_facade.rb create mode 100644 spec/facades/item_facade_spec.rb diff --git a/app/facades/item_facade.rb b/app/facades/item_facade.rb new file mode 100644 index 00000000..1c8356b5 --- /dev/null +++ b/app/facades/item_facade.rb @@ -0,0 +1,10 @@ +class ItemFacade + def self.all_items + response = RailsEngineService.get_all_items + items = response[:data] + + items.map do |data| + Item.new(data) + end + end +end \ No newline at end of file diff --git a/spec/facades/item_facade_spec.rb b/spec/facades/item_facade_spec.rb new file mode 100644 index 00000000..670a9f28 --- /dev/null +++ b/spec/facades/item_facade_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +RSpec.describe ItemFacade do + describe 'Item calls' do + it 'all_items' do + items = ItemFacade.all_items + + expect(items).to be_a(Array) + + items.each do |item| + expect(item).to be_instance_of(Item) + end + expect(items[0].name).to eq("Item Nemo Facere") + expect(items[1].name).to eq("Item Expedita Aliquam") + end + end +end \ No newline at end of file From 514db432b11daa9e1b9cb87da09a3bded8e1c9b2 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:37:13 -0700 Subject: [PATCH 13/18] Adds view for /items page --- app/controllers/items_controller.rb | 5 +++++ app/views/items/index.html.erb | 5 +++++ config/routes.rb | 1 + 3 files changed, 11 insertions(+) create mode 100644 app/controllers/items_controller.rb create mode 100644 app/views/items/index.html.erb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb new file mode 100644 index 00000000..787f66ad --- /dev/null +++ b/app/controllers/items_controller.rb @@ -0,0 +1,5 @@ +class ItemsController < ApplicationController + def index + @items = ItemFacade.all_items + end +end \ No newline at end of file diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb new file mode 100644 index 00000000..02a33b49 --- /dev/null +++ b/app/views/items/index.html.erb @@ -0,0 +1,5 @@ +

Items

+ +<% @items.each do |item| %> +

<%= item.name %>

+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a853a5d0..2b74236f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,4 +2,5 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :merchants, only:[:index, :show] + resources :items, only:[:index] end From 3b1cbdfc09c664203e2c1b9701d6e68eb1d877be Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:40:37 -0700 Subject: [PATCH 14/18] Turns all items into links to their show page --- app/views/items/index.html.erb | 2 +- config/routes.rb | 2 +- spec/features/items/items_index_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb index 02a33b49..4dd4727d 100644 --- a/app/views/items/index.html.erb +++ b/app/views/items/index.html.erb @@ -1,5 +1,5 @@

Items

<% @items.each do |item| %> -

<%= item.name %>

+

<%= link_to item.name, "/items/#{item.id}" %>

<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2b74236f..48ff1474 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,5 +2,5 @@ # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :merchants, only:[:index, :show] - resources :items, only:[:index] + resources :items, only:[:index, :show] end diff --git a/spec/features/items/items_index_spec.rb b/spec/features/items/items_index_spec.rb index b57a3acb..01ee40dd 100644 --- a/spec/features/items/items_index_spec.rb +++ b/spec/features/items/items_index_spec.rb @@ -15,4 +15,12 @@ expect(page).to have_content("Item Rerum Magni") end end + + it 'can click on an items name and be directed to that items show page' do + visit '/items' + + click_link "Item Nemo Facere" + + expect(current_path).to eq("/items/4") + end end From ef55c6cc68e35f884c23293c80543f1fa35562d5 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:46:06 -0700 Subject: [PATCH 15/18] Adds #elf.get_one_item to service --- app/services/rails_engine_service.rb | 5 +++++ spec/services/rails_engine_service_spec.rb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/services/rails_engine_service.rb b/app/services/rails_engine_service.rb index 85f9bee0..a302c5c4 100644 --- a/app/services/rails_engine_service.rb +++ b/app/services/rails_engine_service.rb @@ -26,4 +26,9 @@ def self.get_all_items response = conn.get('items') json_parse(response) end + + def self.get_one_item(item_id) + response = conn.get("items/#{item_id}") + json_parse(response) + end end \ No newline at end of file diff --git a/spec/services/rails_engine_service_spec.rb b/spec/services/rails_engine_service_spec.rb index b2f83fee..15a5282a 100644 --- a/spec/services/rails_engine_service_spec.rb +++ b/spec/services/rails_engine_service_spec.rb @@ -66,4 +66,20 @@ end end end + + describe 'get_one_item' do + it 'gets an item based on id' do + response = RailsEngineService.get_one_item(179) + + expect(response).to have_key(:data) + expect(response[:data]).to be_a(Hash) + expect(response[:data]).to have_key(:id) + expect(response[:data][:attributes]).to have_key(:name) + expect(response[:data][:attributes]).to have_key(:description) + expect(response[:data][:attributes]).to have_key(:unit_price) + + expect(response[:data][:id]).to eq("179") + expect(response[:data][:attributes][:name]).to eq("Item Qui Veritatis") + end + end end \ No newline at end of file From 3d211d25f8693a818c336a9ba65107123c435b16 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:49:54 -0700 Subject: [PATCH 16/18] Adds #self.one_item to ItemFacade --- app/facades/item_facade.rb | 5 +++++ spec/facades/item_facade_spec.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/facades/item_facade.rb b/app/facades/item_facade.rb index 1c8356b5..c0361a0a 100644 --- a/app/facades/item_facade.rb +++ b/app/facades/item_facade.rb @@ -7,4 +7,9 @@ def self.all_items Item.new(data) end end + + def self.one_item(item_id) + response = RailsEngineService.get_one_item(item_id) + Item.new(response[:data]) + end end \ No newline at end of file diff --git a/spec/facades/item_facade_spec.rb b/spec/facades/item_facade_spec.rb index 670a9f28..b279811a 100644 --- a/spec/facades/item_facade_spec.rb +++ b/spec/facades/item_facade_spec.rb @@ -13,5 +13,16 @@ expect(items[0].name).to eq("Item Nemo Facere") expect(items[1].name).to eq("Item Expedita Aliquam") end + + it 'one_item' do + item = ItemFacade.one_item(179) + + expect(item).to be_instance_of(Item) + + expect(item.id).to eq("179") + expect(item.name).to eq("Item Qui Veritatis") + expect(item.description).to eq("Totam labore quia harum dicta eum consequatur qui. Corporis inventore consequatur. Illum facilis tempora nihil placeat rerum sint est. Placeat ut aut. Eligendi perspiciatis unde eum sapiente velit.") + expect(item.unit_price).to eq(906.17) + end end end \ No newline at end of file From 8cf3b1becb210472b98cb21d353524fdb9b64491 Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:52:02 -0700 Subject: [PATCH 17/18] Adds view for item show --- app/controllers/items_controller.rb | 4 ++++ app/views/items/show.html.erb | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 app/views/items/show.html.erb diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 787f66ad..f74f1f1f 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -2,4 +2,8 @@ class ItemsController < ApplicationController def index @items = ItemFacade.all_items end + + def show + @item = ItemFacade.one_item(params[:id]) + end end \ No newline at end of file diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb new file mode 100644 index 00000000..27516183 --- /dev/null +++ b/app/views/items/show.html.erb @@ -0,0 +1,3 @@ +

<%= @item.name %>

+ +<%= @item.description %> \ No newline at end of file From deb71f7fe1001f5fb949a9197887bc969671283f Mon Sep 17 00:00:00 2001 From: Leo Banos Garcia Date: Thu, 16 Feb 2023 09:58:11 -0700 Subject: [PATCH 18/18] Adds unit price and description to an items show page --- app/views/items/show.html.erb | 3 ++- spec/features/items/item_show_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 spec/features/items/item_show_spec.rb diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 27516183..9eae47e1 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -1,3 +1,4 @@

<%= @item.name %>

-<%= @item.description %> \ No newline at end of file +

Description: <%= @item.description %>

+

Unit price: $<%= @item.unit_price %>

\ No newline at end of file diff --git a/spec/features/items/item_show_spec.rb b/spec/features/items/item_show_spec.rb new file mode 100644 index 00000000..c35bd79c --- /dev/null +++ b/spec/features/items/item_show_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "Item show" do + it 'an items show page will list a description and unit price' do + visit "/items/45" + + expect(page).to have_content("Item Id Aut") + expect(page).to have_content("Description: Blanditiis alias cupiditate dolores. Cum architecto est magnam similique quis culpa est. Incidunt consequatur sunt maxime veritatis labore officia. Quaerat nemo molestias et omnis quia.") + expect(page).to have_content("Unit price: $318.76") + end +end \ No newline at end of file