add zone test-rspec
This commit is contained in:
3
app/assets/javascripts/api/restaurant/zone.coffee
Normal file
3
app/assets/javascripts/api/restaurant/zone.coffee
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||||
3
app/assets/stylesheets/api/restaurant/zone.scss
Normal file
3
app/assets/stylesheets/api/restaurant/zone.scss
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the api/restaurant/zone controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||||
4
app/controllers/api/restaurant/zone_controller.rb
Normal file
4
app/controllers/api/restaurant/zone_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class Api::Restaurant::ZoneController < ApplicationController
|
||||||
|
def index
|
||||||
|
end
|
||||||
|
end
|
||||||
2
app/helpers/api/restaurant/zone_helper.rb
Normal file
2
app/helpers/api/restaurant/zone_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module Api::Restaurant::ZoneHelper
|
||||||
|
end
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
class SeatTable < ApplicationRecord
|
class SeatTable < ApplicationRecord
|
||||||
belongs_to :zone
|
belongs_to :zone
|
||||||
|
|
||||||
|
# validations
|
||||||
|
validates_presence_of :name,:order_by, :created_by
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,7 @@
|
|||||||
class Zone < ApplicationRecord
|
class Zone < ApplicationRecord
|
||||||
|
# model association
|
||||||
|
has_many :seat_tables, dependent: :destroy
|
||||||
|
|
||||||
|
# validations
|
||||||
|
validates_presence_of :name, :created_by
|
||||||
end
|
end
|
||||||
|
|||||||
2
app/views/api/restaurant/zone/index.html.erb
Normal file
2
app/views/api/restaurant/zone/index.html.erb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<h1>Api::Restaurant::Zone#index</h1>
|
||||||
|
<p>Find me in app/views/api/restaurant/zone/index.html.erb</p>
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
namespace :api do
|
||||||
|
namespace :restaurant do
|
||||||
|
get 'zone/index'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ class CreateZones < ActiveRecord::Migration[5.0]
|
|||||||
create_table :zones do |t|
|
create_table :zones do |t|
|
||||||
t.string :name, :null => false
|
t.string :name, :null => false
|
||||||
t.boolean :is_active, :default => true
|
t.boolean :is_active, :default => true
|
||||||
|
t.string :created_by
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class CreateSeatTables < ActiveRecord::Migration[5.0]
|
|||||||
t.string :table_type, :null => false, :default => "square"
|
t.string :table_type, :null => false, :default => "square"
|
||||||
t.float :position_x, :null => false, :default => 0.0
|
t.float :position_x, :null => false, :default => 0.0
|
||||||
t.float :position_y, :null => false, :default => 0.0
|
t.float :position_y, :null => false, :default => 0.0
|
||||||
|
t.string :created_by
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
12
spec/controllers/api/restaurant/zone_controller_spec.rb
Normal file
12
spec/controllers/api/restaurant/zone_controller_spec.rb
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Api::Restaurant::ZoneController, type: :controller do
|
||||||
|
|
||||||
|
describe "GET #index" do
|
||||||
|
it "returns http success" do
|
||||||
|
get :index
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
8
spec/factories/seat_tables.rb
Normal file
8
spec/factories/seat_tables.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :seat_tables do
|
||||||
|
name { Faker::StarWars.character }
|
||||||
|
order_by { Faker::Number.number(5)}
|
||||||
|
no_of_seater {Faker::Number.number(5)}
|
||||||
|
zone_id nil
|
||||||
|
end
|
||||||
|
end
|
||||||
6
spec/factories/zones.rb
Normal file
6
spec/factories/zones.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :zone do
|
||||||
|
name { Faker::Lorem.word }
|
||||||
|
created_by { Faker::StarWars.character }
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe SeatTable, type: :model do
|
RSpec.describe SeatTable, type: :model do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
# Association test
|
||||||
|
# ensure an item record belongs to a single todo record
|
||||||
|
it { should belong_to(:zone) }
|
||||||
|
# Validation test
|
||||||
|
# ensure column name is present before saving
|
||||||
|
it { should validate_presence_of(:name) }
|
||||||
|
it { should validate_presence_of(:order_by) }
|
||||||
|
it { should validate_presence_of(:created_by) }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Zone, type: :model do
|
RSpec.describe Zone, type: :model do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
# Association test
|
||||||
|
# ensure Todo model has a 1:m relationship with the Item model
|
||||||
|
it { should have_many(:seat_tables).dependent(:destroy) }
|
||||||
|
# Validation tests
|
||||||
|
# ensure columns title and created_by are present before saving
|
||||||
|
it { should validate_presence_of(:name) }
|
||||||
|
it { should validate_presence_of(:created_by) }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ require 'database_cleaner'
|
|||||||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||||
# require only the support files necessary.
|
# require only the support files necessary.
|
||||||
#
|
#
|
||||||
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
||||||
|
|
||||||
# Checks for pending migration and applies them before tests are run.
|
# Checks for pending migration and applies them before tests are run.
|
||||||
# If you are not using ActiveRecord, you can remove this line.
|
# If you are not using ActiveRecord, you can remove this line.
|
||||||
@@ -43,6 +43,9 @@ RSpec.configure do |config|
|
|||||||
# add `FactoryGirl` methods
|
# add `FactoryGirl` methods
|
||||||
config.include FactoryGirl::Syntax::Methods
|
config.include FactoryGirl::Syntax::Methods
|
||||||
|
|
||||||
|
config.include RequestSpecHelper, type: :request
|
||||||
|
|
||||||
|
|
||||||
# start by truncating all the tables but then use the faster transaction strategy the rest of the time.
|
# start by truncating all the tables but then use the faster transaction strategy the rest of the time.
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
DatabaseCleaner.clean_with(:truncation)
|
DatabaseCleaner.clean_with(:truncation)
|
||||||
|
|||||||
0
spec/requests/api/restaurant/seat_tables.rb
Normal file
0
spec/requests/api/restaurant/seat_tables.rb
Normal file
25
spec/requests/api/restaurant/zones.rb
Normal file
25
spec/requests/api/restaurant/zones.rb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'Zone API', type: :request do
|
||||||
|
# initialize test data
|
||||||
|
let!(:zone) { create_list(:zone, 10) }
|
||||||
|
let(:zone_id) { zones.first.id }
|
||||||
|
|
||||||
|
# Test suite for GET /todos
|
||||||
|
describe 'GET /api/restaurant/zones' do
|
||||||
|
# make HTTP get request before each example
|
||||||
|
before { get '/api/restaurant/zones' }
|
||||||
|
|
||||||
|
it 'returns zones' do
|
||||||
|
# Note `json` is a custom helper to parse JSON responses
|
||||||
|
expect(json).not_to be_empty
|
||||||
|
expect(json.size).to eq(10)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns status code 200' do
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
7
spec/support/request_spec_helper.rb
Normal file
7
spec/support/request_spec_helper.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# spec/support/request_spec_helper
|
||||||
|
module RequestSpecHelper
|
||||||
|
# Parse JSON response to ruby hash
|
||||||
|
def json
|
||||||
|
JSON.parse(response.body)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user