Skip to content

Commit

Permalink
Add the calendar model and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
getschomp committed Jan 12, 2017
1 parent d6b31e9 commit ee22705
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 8 deletions.
30 changes: 30 additions & 0 deletions app/models/nodes/calendar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Nodes
class Calendar
include Neo4j::ActiveNode

property :service_id, type: Integer
property :monday, type: Integer
property :tuesday, type: Integer
property :wednesday, type: Integer
property :thursday, type: Integer
property :friday, type: Integer
property :saturday, type: Integer
property :sunday, type: Integer
property :start_date, type: String
property :end_date, type: String

property :created_at
property :updated_at

validates :service_id, presence: true
validates :monday, presence: true, inclusion: { in: 0..1}
validates :tuesday, presence: true, inclusion: { in: 0..1}
validates :wednesday, presence: true, inclusion: { in: 0..1}
validates :thursday, presence: true, inclusion: { in: 0..1}
validates :friday, presence: true, inclusion: { in: 0..1}
validates :saturday, presence: true, inclusion: { in: 0..1}
validates :sunday, presence: true, inclusion: { in: 0..1}
validates :start_date, presence: true, length: { is: 8 }
validates :end_date, presence: true, length: { is: 8 }
end
end
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"covered_percent": 98.83
"covered_percent": 98.97
}
}
90 changes: 84 additions & 6 deletions coverage/.resultset.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@
null,
1,
1,
7,
8,
null,
null,
1,
1,
null,
1,
null,
11,
11,
13,
13,
null,
null,
1,
11,
13,
null,
null,
1,
Expand Down Expand Up @@ -343,6 +343,38 @@
null,
null
],
"/Users/Allison/commute_calculator/app/models/nodes/calendar.rb": [
1,
1,
1,
null,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
null,
1,
1,
null,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
null,
null
],
"/Users/Allison/commute_calculator/app/models/services/authenticator.rb": [
1,
1,
Expand Down Expand Up @@ -513,7 +545,29 @@
1,
null
],
"/Users/Allison/commute_calculator/spec/models/node_agency_spec.rb": [
"/Users/Allison/commute_calculator/spec/models/nodes_agency_spec.rb": [
1,
null,
1,
1,
1,
1,
null,
null,
null,
1,
null,
null,
1,
1,
null,
1,
1,
null,
null,
null
],
"/Users/Allison/commute_calculator/spec/models/nodes_calendar_spec.rb": [
1,
null,
1,
Expand All @@ -522,16 +576,40 @@
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
null,
1,
1,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
1,
null,
null,
null,
null,
null,
null,
null,
null
],
"/Users/Allison/commute_calculator/spec/models/user_spec.rb": [
Expand Down Expand Up @@ -704,6 +782,6 @@
null
]
},
"timestamp": 1484180280
"timestamp": 1484184831
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ForceCreateNodesCalendarUuidConstraint < Neo4j::Migrations::Base
def up
add_constraint :"Nodes::Calendar", :uuid, force: true
end

def down
drop_constraint :"Nodes::Calendar", :uuid
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
describe '.create' do
it 'persists a user with valid attributes' do
agency = Nodes::Agency.create(
name: 'Trans-Siberian', url: 'www.ts.com', timezone: 'OMST')
name: 'Trans-Siberian', url: 'www.ts.com', timezone: 'OMST'
)

expect(agency).to be_persisted
end
Expand Down
43 changes: 43 additions & 0 deletions spec/models/nodes_calendar_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require 'rails_helper'

describe Nodes::Calendar do
describe '.create' do
it 'persists a user with valid attributes' do
calendar = Nodes::Calendar.create(
service_id: 20,
monday: 0,
tuesday: 1,
wednesday: 0,
thursday: 1,
friday: 1,
saturday: 0,
sunday: 1,
start_date: '20170101',
end_date: '20171208'
)

expect(calendar).to be_persisted
end

it 'does not persist if attributes are not valid' do
calendar = Nodes::Calendar.create(
service_id: 20,
monday: 0,
tuesday: 1,
wednesday: 0,
saturday: 9,
sunday: 1,
start_date: '20170101',
end_date: '20171208754'
)

expect(calendar).not_to be_persisted
expect(calendar.errors.messages).to eq(
thursday: ["can't be blank", "is not included in the list"],
friday: ["can't be blank", "is not included in the list"],
saturday: ["is not included in the list"],
end_date: ["is the wrong length (should be 8 characters)"]
)
end
end
end

0 comments on commit ee22705

Please sign in to comment.