added rspec model specs for all models with FactoryGirl and proper association … | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit 86e1f2eb6b2e170a8ce01ca7503a606475d0b75a | |
parent c25db678ded165b56d64d94bddd23d98e6f97e0e | |
Author: zeknox <[email protected]> | |
Date: Fri, 23 Oct 2015 18:37:45 -0500 | |
added rspec model specs for all models with FactoryGirl and proper association … | |
Diffstat: | |
M app/models/project.rb | 3 +-- | |
A spec/factories/call_media.rb | 23 +++++++++++++++++++++++ | |
M spec/factories/calls.rb | 9 ++++++--- | |
A spec/factories/jobs.rb | 34 +++++++++++++++++++++++++++++… | |
A spec/factories/lines.rb | 20 ++++++++++++++++++++ | |
A spec/factories/projects.rb | 21 +++++++++++++++++++++ | |
A spec/factories/providers.rb | 28 ++++++++++++++++++++++++++++ | |
A spec/factories/settings.rb | 19 +++++++++++++++++++ | |
A spec/factories/signature_fps.rb | 6 ++++++ | |
A spec/factories/signatures.rb | 26 ++++++++++++++++++++++++++ | |
M spec/factories/users.rb | 14 +++++++------- | |
A spec/models/call_medium_spec.rb | 26 ++++++++++++++++++++++++++ | |
M spec/models/call_spec.rb | 14 +++++++------- | |
A spec/models/job_spec.rb | 32 +++++++++++++++++++++++++++++… | |
A spec/models/line_spec.rb | 23 +++++++++++++++++++++++ | |
A spec/models/project_spec.rb | 30 ++++++++++++++++++++++++++++++ | |
A spec/models/provider_spec.rb | 36 +++++++++++++++++++++++++++++… | |
A spec/models/settings_spec.rb | 20 ++++++++++++++++++++ | |
A spec/models/signature_fp_spec.rb | 5 +++++ | |
A spec/models/signature_spec.rb | 26 ++++++++++++++++++++++++++ | |
M spec/models/user_spec.rb | 11 +++++------ | |
21 files changed, 401 insertions(+), 25 deletions(-) | |
--- | |
diff --git a/app/models/project.rb b/app/models/project.rb | |
@@ -14,9 +14,8 @@ | |
class Project < ActiveRecord::Base | |
- | |
- validates :name, :uniqueness => true | |
validates_presence_of :name | |
+ validates_uniqueness_of :name | |
attr_accessible :name, :description, :included, :excluded | |
diff --git a/spec/factories/call_media.rb b/spec/factories/call_media.rb | |
@@ -0,0 +1,23 @@ | |
+# == Schema Information | |
+# | |
+# Table name: call_media | |
+# | |
+# id :integer not null, primary key | |
+# call_id :integer not null | |
+# project_id :integer not null | |
+# audio :binary | |
+# mp3 :binary | |
+# png_big :binary | |
+# png_big_dots :binary | |
+# png_big_freq :binary | |
+# png_sig :binary | |
+# png_sig_freq :binary | |
+# | |
+ | |
+FactoryGirl.define do | |
+ factory :call_medium do | |
+ call | |
+ project | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/calls.rb b/spec/factories/calls.rb | |
@@ -25,8 +25,11 @@ | |
# | |
FactoryGirl.define do | |
- factory :call do | |
- number { Faker::PhoneNumber.phone_number } | |
- end | |
+ factory :call do | |
+ project | |
+ job | |
+ provider | |
+ number { Faker::PhoneNumber.phone_number } | |
+ end | |
end | |
diff --git a/spec/factories/jobs.rb b/spec/factories/jobs.rb | |
@@ -0,0 +1,34 @@ | |
+# == Schema Information | |
+# | |
+# Table name: jobs | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# project_id :integer not null | |
+# locked_by :string(255) | |
+# locked_at :datetime | |
+# started_at :datetime | |
+# completed_at :datetime | |
+# created_by :string(255) | |
+# task :string(255) not null | |
+# args :binary | |
+# status :string(255) | |
+# error :text | |
+# progress :integer default(0) | |
+# | |
+ | |
+FactoryGirl.define do | |
+ factory :job do | |
+ project | |
+ task 'dialer' | |
+ args "\x04\b{\t:\nrangeI\"\x0F7632458942\x06:\x06ET:\nlinesi\x… | |
+ status 'submitted' | |
+ error nil | |
+ range { Faker::PhoneNumber.phone_number } | |
+ cid_mask { Faker::PhoneNumber.phone_number } | |
+ seconds { Faker::Number.between(1, 300) } | |
+ lines { Faker::Number.between(1, 10000) } | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/lines.rb b/spec/factories/lines.rb | |
@@ -0,0 +1,20 @@ | |
+# == Schema Information | |
+# | |
+# Table name: lines | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# number :text not null | |
+# project_id :integer not null | |
+# line_type :text | |
+# notes :text | |
+# | |
+ | |
+FactoryGirl.define do | |
+ factory :line do | |
+ project | |
+ number { Faker::PhoneNumber.phone_number } | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/projects.rb b/spec/factories/projects.rb | |
@@ -0,0 +1,21 @@ | |
+# == Schema Information | |
+# | |
+# Table name: projects | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# name :text not null | |
+# description :text | |
+# included :text | |
+# excluded :text | |
+# created_by :string(255) | |
+# | |
+ | |
+FactoryGirl.define do | |
+ factory :project do | |
+ name { Faker::Lorem.sentence } | |
+ description { Faker::Lorem.sentence } | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/providers.rb b/spec/factories/providers.rb | |
@@ -0,0 +1,28 @@ | |
+# == Schema Information | |
+# | |
+# Table name: providers | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# name :text not null | |
+# host :text not null | |
+# port :integer not null | |
+# user :text | |
+# pass :text | |
+# lines :integer default(1), not null | |
+# enabled :boolean default(TRUE) | |
+# | |
+ | |
+FactoryGirl.define do | |
+ factory :provider do | |
+ name { Faker::Company.name } | |
+ host { Faker::Internet.ip_v4_address } | |
+ port { Faker::Number.between(1, 65535) } | |
+ user { Faker::Internet.user_name } | |
+ pass { Faker::Internet.password(10, 20) } | |
+ lines { Faker::Number.between(1, 254) } | |
+ enabled true | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/settings.rb b/spec/factories/settings.rb | |
@@ -0,0 +1,19 @@ | |
+# == Schema Information | |
+# | |
+# Table name: settings | |
+# | |
+# id :integer not null, primary key | |
+# var :string(255) not null | |
+# value :text | |
+# thing_id :integer | |
+# thing_type :string(30) | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# | |
+ | |
+FactoryGirl.define do | |
+ factory :setting, :class => 'Settings' do | |
+ var "CachedStuff" | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/signature_fps.rb b/spec/factories/signature_fps.rb | |
@@ -0,0 +1,6 @@ | |
+FactoryGirl.define do | |
+ factory :signature_fp do | |
+ | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/signatures.rb b/spec/factories/signatures.rb | |
@@ -0,0 +1,26 @@ | |
+# == Schema Information | |
+# | |
+# Table name: signatures | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# name :text not null | |
+# source :string(255) | |
+# description :text | |
+# category :string(255) | |
+# line_type :string(255) | |
+# risk :integer | |
+# | |
+ | |
+FactoryGirl.define do | |
+ factory :signature do | |
+ name { Faker::Commerce.product_name } | |
+ source { Faker::PhoneNumber.cell_phone } | |
+ description { Faker::Lorem.sentence } | |
+ category { Faker::Lorem.word } | |
+ line_type { Faker::Lorem.word } | |
+ risk { Faker::Lorem.word } | |
+ end | |
+ | |
+end | |
diff --git a/spec/factories/users.rb b/spec/factories/users.rb | |
@@ -24,12 +24,12 @@ | |
# | |
FactoryGirl.define do | |
- factory :user do | |
- login { Faker::Internet.user_name } | |
- password 'RandomPass' | |
- password_confirmation 'RandomPass' | |
- enabled true | |
- admin true | |
- end | |
+ factory :user do | |
+ login { Faker::Internet.user_name } | |
+ password 'RandomPass' | |
+ password_confirmation 'RandomPass' | |
+ enabled true | |
+ admin true | |
+ end | |
end | |
diff --git a/spec/models/call_medium_spec.rb b/spec/models/call_medium_spec.rb | |
@@ -0,0 +1,26 @@ | |
+# == Schema Information | |
+# | |
+# Table name: call_media | |
+# | |
+# id :integer not null, primary key | |
+# call_id :integer not null | |
+# project_id :integer not null | |
+# audio :binary | |
+# mp3 :binary | |
+# png_big :binary | |
+# png_big_dots :binary | |
+# png_big_freq :binary | |
+# png_sig :binary | |
+# png_sig_freq :binary | |
+# | |
+ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe CallMedium, type: :model do | |
+ it { should belong_to(:call) } | |
+ it { should belong_to(:project) } | |
+ | |
+ it "valid record" do | |
+ expect(build(:call_medium)).to be_valid | |
+ end | |
+end | |
diff --git a/spec/models/call_spec.rb b/spec/models/call_spec.rb | |
@@ -27,12 +27,12 @@ | |
require 'rails_helper' | |
RSpec.describe Call, type: :model do | |
- it { should belong_to(:project) } | |
- it { should belong_to(:provider) } | |
- it { should belong_to(:job) } | |
- it { should have_one(:call_medium).dependent(:delete) } | |
+ it { should belong_to(:project) } | |
+ it { should belong_to(:provider) } | |
+ it { should belong_to(:job) } | |
+ it { should have_one(:call_medium).dependent(:delete) } | |
- it "valid record" do | |
- expect(build(:call)).to be_valid | |
- end | |
+ it "valid record" do | |
+ expect(build(:call)).to be_valid | |
+ end | |
end | |
diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb | |
@@ -0,0 +1,32 @@ | |
+# == Schema Information | |
+# | |
+# Table name: jobs | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# project_id :integer not null | |
+# locked_by :string(255) | |
+# locked_at :datetime | |
+# started_at :datetime | |
+# completed_at :datetime | |
+# created_by :string(255) | |
+# task :string(255) not null | |
+# args :binary | |
+# status :string(255) | |
+# error :text | |
+# progress :integer default(0) | |
+# | |
+ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe Job, type: :model do | |
+ it { should belong_to(:project) } | |
+ it { should have_many(:calls) } | |
+ | |
+ it { should validate_presence_of(:project_id) } | |
+ | |
+ it "valid record" do | |
+ expect(build(:job)).to be_valid | |
+ end | |
+end | |
diff --git a/spec/models/line_spec.rb b/spec/models/line_spec.rb | |
@@ -0,0 +1,23 @@ | |
+# == Schema Information | |
+# | |
+# Table name: lines | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# number :text not null | |
+# project_id :integer not null | |
+# line_type :text | |
+# notes :text | |
+# | |
+ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe Line, type: :model do | |
+ it { should belong_to(:project) } | |
+ it { should have_many(:line_attributes).dependent(:delete_all) } | |
+ | |
+ it "valid record" do | |
+ expect(build(:line)).to be_valid | |
+ end | |
+end | |
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb | |
@@ -0,0 +1,30 @@ | |
+# == Schema Information | |
+# | |
+# Table name: projects | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# name :text not null | |
+# description :text | |
+# included :text | |
+# excluded :text | |
+# created_by :string(255) | |
+# | |
+ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe Project, type: :model do | |
+ it { should have_many(:lines).dependent(:delete_all) } | |
+ it { should have_many(:line_attributes).dependent(:delete_all) } | |
+ it { should have_many(:calls).dependent(:delete_all) } | |
+ it { should have_many(:call_media).dependent(:delete_all) } | |
+ it { should have_many(:jobs).dependent(:delete_all) } | |
+ | |
+ it { should validate_presence_of(:name) } | |
+ it { should validate_uniqueness_of(:name) } | |
+ | |
+ it "valid record" do | |
+ expect(build(:project)).to be_valid | |
+ end | |
+end | |
diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb | |
@@ -0,0 +1,36 @@ | |
+# == Schema Information | |
+# | |
+# Table name: providers | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# name :text not null | |
+# host :text not null | |
+# port :integer not null | |
+# user :text | |
+# pass :text | |
+# lines :integer default(1), not null | |
+# enabled :boolean default(TRUE) | |
+# | |
+ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe Provider, type: :model do | |
+ ## TODO determine if association is unecessary | |
+ # the DialResult model does not exist | |
+ #it { should have_many(:dial_results) } | |
+ | |
+ it { should validate_presence_of(:name) } | |
+ it { should validate_presence_of(:host) } | |
+ it { should validate_presence_of(:port) } | |
+ it { should validate_presence_of(:user) } | |
+ it { should validate_presence_of(:pass) } | |
+ it { should validate_presence_of(:lines) } | |
+ it { should validate_numericality_of(:port).is_less_than(65536).is_gre… | |
+ it { should validate_numericality_of(:lines).is_less_than(255).is_grea… | |
+ | |
+ it "valid record" do | |
+ expect(build(:provider)).to be_valid | |
+ end | |
+end | |
diff --git a/spec/models/settings_spec.rb b/spec/models/settings_spec.rb | |
@@ -0,0 +1,20 @@ | |
+# == Schema Information | |
+# | |
+# Table name: settings | |
+# | |
+# id :integer not null, primary key | |
+# var :string(255) not null | |
+# value :text | |
+# thing_id :integer | |
+# thing_type :string(30) | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# | |
+ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe Settings, type: :model do | |
+ it "valid record" do | |
+ expect(build(:setting)).to be_valid | |
+ end | |
+end | |
diff --git a/spec/models/signature_fp_spec.rb b/spec/models/signature_fp_spec.rb | |
@@ -0,0 +1,5 @@ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe SignatureFp, type: :model do | |
+ | |
+end | |
diff --git a/spec/models/signature_spec.rb b/spec/models/signature_spec.rb | |
@@ -0,0 +1,26 @@ | |
+# == Schema Information | |
+# | |
+# Table name: signatures | |
+# | |
+# id :integer not null, primary key | |
+# created_at :datetime | |
+# updated_at :datetime | |
+# name :text not null | |
+# source :string(255) | |
+# description :text | |
+# category :string(255) | |
+# line_type :string(255) | |
+# risk :integer | |
+# | |
+ | |
+require 'rails_helper' | |
+ | |
+RSpec.describe Signature, type: :model do | |
+ ## TODO association may not be needed | |
+ # causes crash: PG::UndefinedTable: ERROR: relation "signature_fps" … | |
+ #it { should have_many(:signature_fps) } | |
+ | |
+ it "valid record" do | |
+ expect(build(:signature)).to be_valid | |
+ end | |
+end | |
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb | |
@@ -26,11 +26,10 @@ | |
require 'rails_helper' | |
RSpec.describe User, type: :model do | |
- it { should validate_length_of(:password).is_at_least(8) } | |
- it { should validate_length_of(:password_confirmation).is_at_least(8) } | |
+ it { should validate_length_of(:password).is_at_least(8) } | |
+ it { should validate_length_of(:password_confirmation).is_at_least(8) } | |
- it 'valid record' do | |
- user = build(:user) | |
- expect(user).to be_valid | |
- end | |
+ it 'valid record' do | |
+ expect(build(:user)).to be_valid | |
+ end | |
end |