add zone test-rspec
This commit is contained in:
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'
|
||||
|
||||
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
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
require 'rails_helper'
|
||||
|
||||
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
|
||||
|
||||
@@ -22,7 +22,7 @@ require 'database_cleaner'
|
||||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||
# 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.
|
||||
# If you are not using ActiveRecord, you can remove this line.
|
||||
@@ -43,6 +43,9 @@ RSpec.configure do |config|
|
||||
# add `FactoryGirl` 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.
|
||||
config.before(:suite) do
|
||||
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