mirror of
https://github.com/fspc/bike-database.git
synced 2025-02-23 01:23:24 -05:00
lk | adds tests & validations to client
This commit is contained in:
parent
9e1f397fd7
commit
6b2a824f66
@ -1,12 +1,13 @@
|
|||||||
class Client < ActiveRecord::Base
|
class Client < ActiveRecord::Base
|
||||||
|
validates :application_date, presence: true
|
||||||
has_one :bike
|
has_one :bike
|
||||||
belongs_to :agency
|
belongs_to :agency
|
||||||
|
|
||||||
def self.waiting_list
|
def self.waiting_list
|
||||||
clients = Client.all
|
clients = Client.all
|
||||||
non_voided_clients = clients.select{|client| !client.application_voided}
|
non_voided_clients = clients.select{|client| !client.application_voided}
|
||||||
incomplete_clients = non_voided_clients.select{|client| !client.completion_date}
|
waiting_list = non_voided_clients.select{|client| !client.completion_date}
|
||||||
waiting_list = incomplete_clients.sort_by!{|client| client.application_date}
|
waiting_list.sort_by!{|client| client.application_date}
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :random_client do
|
factory :client do
|
||||||
first_name "John"
|
first_name "John"
|
||||||
last_name "Doe"
|
last_name "Doe"
|
||||||
application_date Date.new(2010, 03, 02)
|
application_date Date.new(2010, 03, 02)
|
||||||
gender "Male"
|
gender "Male"
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,22 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Client do
|
describe Client do
|
||||||
|
describe "#waiting_list" do
|
||||||
|
it "does not include voided clients" do
|
||||||
|
create(:client, application_voided: true)
|
||||||
|
expect(Client.waiting_list).to be_empty
|
||||||
|
end
|
||||||
|
it "orders clients by application date" do
|
||||||
|
client_2 = create(:client, application_date: 2.weeks.ago)
|
||||||
|
client_1 = create(:client, application_date: 3.weeks.ago)
|
||||||
|
client_3 = create(:client, application_date: 1.weeks.ago)
|
||||||
|
expect(Client.waiting_list).to eq([client_1, client_2, client_3])
|
||||||
|
|
||||||
|
end
|
||||||
|
it "does not include completed clients" do
|
||||||
|
create(:client, completion_date: 1.week.ago)
|
||||||
|
expect(Client.waiting_list).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
ENV["RAILS_ENV"] ||= 'test'
|
ENV["RAILS_ENV"] ||= 'test'
|
||||||
require File.expand_path("../../config/environment", __FILE__)
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
require 'rspec/autorun'
|
|
||||||
|
|
||||||
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
||||||
|
|
||||||
@ -13,5 +12,6 @@ RSpec.configure do |config|
|
|||||||
config.use_transactional_fixtures = true
|
config.use_transactional_fixtures = true
|
||||||
config.infer_base_class_for_anonymous_controllers = false
|
config.infer_base_class_for_anonymous_controllers = false
|
||||||
config.include Devise::TestHelpers, type: :controller
|
config.include Devise::TestHelpers, type: :controller
|
||||||
|
config.include FactoryGirl::Syntax::Methods
|
||||||
config.order = "random"
|
config.order = "random"
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user