An E-Commerce Application with a service-oriented architecture. This software exposes data that powers the site through an API.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
- Fork and clone the repo
bundle install- Set up db/seeds.rb file with the following content:
cmd = "pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $(whoami) -d rails-engine_development db/data/rails-engine-development.pgdump"
puts "Loading PostgreSQL Data dump into local database with command:"
puts cmd
system(cmd)
-
Download rails-engine-development.pgdump and move it into the
/db/folder in another folder called/data/ -
Run
rails db:{drop,create,migrate,seed} -
Run tests (See Runing the tests](#running-the-tests) section for more details)
bundle exec rspec -
Start localhostserver
rails s -
Access localhost server in browser
localhost:3000
- All tests: insert
bundle exec rspecin your terminal. requesttests only: insertbundle exec rspec spec/requestsin your terminal.modeltests only: insertbundle exec rspec spec/modelsin your terminal.
Below are two examples of a happy and sad path when trying to destroy an invoice.
it 'can destory an invoice and invoice item' do
expect{ delete "/api/v1/items/#{@item.id}" }.to change(Item, :count).by(-1)
expect(response.status).to eq 204
expect{Invoice.find(@invoice.id)}.to raise_error(ActiveRecord::RecordNotFound)
expect{InvoiceItem.find(@invoice_item.id)}.to raise_error(ActiveRecord::RecordNotFound)
end
it 'cannot destory an invoice because it is linked to another item' do
@item_2 = create(:item)
@invoice_item_2 = create(:invoice_item, item: @item_2, invoice: @invoice)
expect{ delete "/api/v1/items/#{@item.id}" }.to change(Item, :count).by(-1)
expect(response.status).to eq 204
expect(Invoice.find(@invoice.id)).to eq(@invoice)
expect(InvoiceItem.find(@invoice_item_2.id)).to eq(@invoice_item_2)
expect{InvoiceItem.find(@invoice_item.id)}.to raise_error(ActiveRecord::RecordNotFound)
end
- I used
RuboCop- static code analyzer and code formatter - Steps to install RuboCop
- Ruby on Rails
- PostgreSQL
- Faker
- FactoryBot
- RuboCop
- Capybara
- Fast JsonAPI
- RSpec
- Simplecov