TODO: Fix Steps::Update

pull/260/head
Rick Carlino 2016-08-31 13:16:03 -05:00
parent b61931e083
commit bcd8fbb2a7
40 changed files with 225 additions and 178 deletions

View File

@ -10,8 +10,8 @@ module Api
sorry "You can't perform that action. #{exc.message}", 403
end
rescue_from Mongoid::Errors::DocumentNotFound do |exc|
sorry "Can't find #{exc.klass}(s) with ID(s): #{exc.params}", 404
rescue_from ActiveRecord::RecordNotFound do |exc|
sorry "Document not found.", 404
end
rescue_from Mongoid::Errors::InvalidFind do
@ -21,8 +21,8 @@ module Api
end
rescue_from Mongoid::Errors::Validations do |exc|
render json: {error: exc.summary}, status: 422
rescue_from ActiveRecord::RecordInvalid do |exc|
render json: {error: exc.message}, status: 422
end
private

View File

@ -1,11 +1,10 @@
class Regimen < ActiveRecord::Base
field :color, type: String, default: -> { Sequence::COLORS.sample }
field :name
# Regimen gets pluralized strangely by Rails.
# Ocasionally to "regimans".
# This is the workaround.
self.table_name = "regimens"
has_many :regimen_items
belongs_to :device, dependent: :destroy
validates_presence_of :name
validates_uniqueness_of :name, scope: :device_id
validates_inclusion_of :color, in: Sequence::COLORS
validates :email, uniqueness: true
end

View File

@ -1,5 +1,4 @@
class RegimenItem < ActiveRecord::Base
field :time_offset, type: Integer
belongs_to :schedule
belongs_to :regimen
belongs_to :sequence

View File

@ -7,26 +7,18 @@ class Schedule < ActiveRecord::Base
belongs_to :device
validates_presence_of :device_id
# field :start_time, type: Time
# field :end_time, type: Time
# field :next_time, type: Time
# validates_presence_of :next_time
# field :repeat, type: Integer
# field :time_unit
# validates_inclusion_of :time_unit, in: UNITS_OF_TIME
# def schedule
# @schedule ||= IceCube::Schedule.new(start_time, end_time: end_time) do |sch|
# sch.add_recurrence_rule IceCube::Rule.send(time_unit.to_sym, repeat)
# end
# end
def schedule_rules
@schedule_rules ||= IceCube::Schedule.new(start_time, end_time: end_time) do |sch|
sch.add_recurrence_rule IceCube::Rule.send(time_unit.to_sym, repeat)
end
end
def calculate_next_occurence
schedule.next_occurrence
schedule_rules.next_occurrence
end
def between(start, finish)
# Just for reference for later. Probably should just delegate.
schedule.occurrences_between(start, finish)
schedule_rules.occurrences_between(start, finish)
end
end

View File

@ -4,23 +4,26 @@ class Step < ActiveRecord::Base
move_relative pin_write read_parameter read_status write_parameter wait
send_message if_statement read_pin)
# embedded_in :sequence
# field :message_type
# validates :message_type, presence: true
belongs_to :sequence
validates :message_type, presence: true
validates :position, presence: true
# field :command, type: Hash, default: {}
# field :position, type: Integer, default: -> do
# if sequence && sequence.steps.present?
# sequence.steps.size - 1
# else
# 0
# end
# end
# validates :position, presence: true
serialize :command
# http://stackoverflow.com/a/5127684/1064917
after_initialize :init
def init
self.position = 0
# if sequence && sequence.steps.present?
# self[:position] = (sequence.steps.size - 1)
# else
# self[:position] = 0
# end
end
def all_steps
(sequence.try(:steps) || Step.none).order_by(:position.asc)
(sequence.try(:steps) || Step.none).order(position: :asc)
end
def move_to!(position)

View File

@ -1,8 +1,20 @@
### A single system User on the decision support system.
class User < ActiveRecord::Base
belongs_to :device, dependent: :destroy
validates_uniqueness_of :email
devise :database_authenticatable, :registerable, :recoverable, :rememberable,
:trackable, :validatable
# Lazy load a device into the account. Prevents weird edge cases, such as
# device === nil on first login.
def device
Device.where(id: self[:device]).first || Devices::Create.run!(user: self,
uuid: SecureRandom.uuid,
token: SecureRandom.hex)
end
def device_id
self[:device_id] || device.id
end
end

View File

@ -19,7 +19,7 @@ module Sequences
end
def execute
update_attributes(sequence, inputs.except(:user, :sequence, :_id))
update_attributes(sequence, inputs.except(:user, :sequence, :id))
end
end
end

View File

@ -1,3 +1,3 @@
class DeviceSerializer < ActiveModel::Serializer
attributes :_id, :name, :uuid, :token
attributes :id, :name, :uuid, :token
end

View File

@ -1,4 +1,4 @@
class RegimenItemSerializer < ActiveModel::Serializer
# TODO
attributes :_id, :regimen_id, :sequence, :time_offset
attributes :id, :regimen_id, :sequence, :time_offset
end

View File

@ -1,3 +1,3 @@
class RegimenSerializer < ActiveModel::Serializer
attributes :_id, :name, :color, :device_id, :regimen_items
attributes :id, :name, :color, :device_id, :regimen_items
end

View File

@ -1,10 +1,10 @@
class ScheduleSerializer < ActiveModel::Serializer
attributes :_id, :start_time, :end_time, :next_time, :repeat, :time_unit,
attributes :id, :start_time, :end_time, :next_time, :repeat, :time_unit,
:sequence_id, :sequence_name, :calendar
try :url, :sequence
# TODO: This is almost certainly wrong. I shouldn't need to write this method.
def sequence_id
object.sequence._id.to_s
object.sequence.id
end
def sequence_name

View File

@ -1,3 +1,3 @@
class SequenceSerializer < ActiveModel::Serializer
attributes :_id, :name, :color, :steps
attributes :id, :name, :color, :steps
end

View File

@ -1,8 +1,8 @@
class StepSerializer < ActiveModel::Serializer
attributes :_id, :message_type, :command, :sequence_id, :position
attributes :id, :message_type, :command, :sequence_id, :position
# This is almost certainly wrong. I shouldn't need to write this method.
def sequence_id
object.sequence._id.to_s
object.sequence_id
end
end

View File

@ -1,15 +1,41 @@
class CreateEverything < ActiveRecord::Migration
def self.up
execute """
ALTER TABLE schedules
ADD CONSTRAINT check_schedules_time_unit_naming
CHECK (time_unit IN (minutely hourly daily weekly monthly yearly) )
"""
execute """
ALTER TABLE regimens
ADD CONSTRAINT check_regimens_color_naming
CHECK (color IN (blue green yellow orange purple pink gray red) )
"""
end
def self.down
execute """
ALTER TABLE schedules
DROP CONSTRAINT check_schedules_time_unit_naming
"""
execute """
ALTER TABLE regimens
DROP CONSTRAINT check_regimens_color_naming
"""
end
def change
create_table :devices do |t|
t.string :planting_area_id
t.integer :planting_area_id
t.string :uuid
t.string :token
t.string :name
end
create_table :plants do |t|
t.string :device_id
t.string :planting_area_id
t.integer :device_id
t.integer :planting_area_id
t.string :name
t.string :img_url
t.string :icon_url
@ -20,60 +46,54 @@ class CreateEverything < ActiveRecord::Migration
end
create_table :planting_areas do |t|
t.string :width
t.string :length
t.string :device_id
t.integer :width
t.integer :length
t.integer :device_id
end
create_table :regimens do |t|
t.string :color
t.string :name
t.string :device_id
t.integer :device_id
end
create_table :regimen_items do |t|
t.string :time_offset
t.string :schedule_id
t.string :regimen_id
t.string :sequence_id
t.integer :schedule_id
t.integer :regimen_id
t.integer :sequence_id
end
create_table :schedules do |t|
t.string :sequence_id
t.string :device_id
t.string :start_time
t.string :end_time
t.string :next_time
t.string :repeat
t.integer :sequence_id
t.integer :device_id
t.datetime :start_time
t.datetime :end_time
t.datetime :next_time
t.integer :repeat
# minutely hourly daily weekly monthly yearly
t.string :time_unit
end
create_table :sequences do |t|
t.string :schedule_id
t.string :device_id
t.integer :schedule_id
t.integer :device_id
t.string :regimen
t.string :name
t.string :color
end
create_table :steps do |t|
t.string :sequence_id
t.integer :sequence_id
t.string :message_type
t.string :position
end
create_table :commands do |t|
# Was embedded
# key?
# value?
t.string :step_id
t.integer :position
t.text :command
end
### A single system User on the decision support system.
create_table :users do |t|
t.string :device_id
t.integer :device_id
t.string :name
t.string :email, null: false, default: ""
@ -93,5 +113,4 @@ class CreateEverything < ActiveRecord::Migration
end
end
end

View File

@ -13,85 +13,87 @@
ActiveRecord::Schema.define(version: 20160820050202) do
create_table "commands", force: :cascade do |t|
t.string "step_id"
end
create_table "devices", force: :cascade do |t|
t.string "planting_area_id"
t.string "uuid"
t.string "token"
t.string "name"
t.integer "planting_area_id"
t.string "uuid"
t.string "token"
t.string "name"
end
create_table "planting_areas", force: :cascade do |t|
t.string "width"
t.string "length"
t.string "device_id"
t.integer "width"
t.integer "length"
t.integer "device_id"
end
create_table "plants", force: :cascade do |t|
t.string "device_id"
t.string "planting_area_id"
t.string "name"
t.string "img_url"
t.string "icon_url"
t.string "openfarm_slug"
t.string "x"
t.string "y"
t.string "planted_at"
t.integer "device_id"
t.integer "planting_area_id"
t.string "name"
t.string "img_url"
t.string "icon_url"
t.string "openfarm_slug"
t.string "x"
t.string "y"
t.string "planted_at"
end
create_table "regimen_items", force: :cascade do |t|
t.string "time_offset"
t.string "schedule_id"
t.string "regimen_id"
t.string "sequence_id"
t.string "time_offset"
t.integer "schedule_id"
t.integer "regimen_id"
t.integer "sequence_id"
end
create_table "regimens", force: :cascade do |t|
t.string "color"
t.string "name"
t.string "device_id"
t.string "color"
t.string "name"
t.integer "device_id"
end
create_table "schedules", force: :cascade do |t|
t.string "sequence_id"
t.string "device_id"
t.string "start_time"
t.string "end_time"
t.string "next_time"
t.string "repeat"
t.string "time_unit"
t.integer "sequence_id"
t.integer "device_id"
t.datetime "start_time"
t.datetime "end_time"
t.datetime "next_time"
t.integer "repeat"
t.string "time_unit"
end
create_table "sequences", force: :cascade do |t|
t.string "schedule_id"
t.string "device_id"
t.string "regimen"
t.string "name"
t.string "color"
t.integer "schedule_id"
t.integer "device_id"
t.string "regimen"
t.string "name"
t.string "color"
end
create_table "steps", force: :cascade do |t|
t.string "sequence_id"
t.string "message_type"
t.string "position"
t.integer "sequence_id"
t.string "message_type"
t.integer "position"
t.text "command"
end
create_table "users", force: :cascade do |t|
t.string "device_id"
t.string "name"
t.string "email"
t.string "encrypted_password"
t.string "reset_password_token"
t.string "reset_password_sent_at"
t.string "remember_created_at"
t.string "sign_in_count"
t.string "current_sign_in_at"
t.string "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.integer "device_id"
t.string "name"
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end

15
db/structure.sql 100644
View File

@ -0,0 +1,15 @@
CREATE TABLE "schema_migrations" ("version" varchar NOT NULL);
CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version");
CREATE TABLE "devices" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "planting_area_id" integer, "uuid" varchar, "token" varchar, "name" varchar);
CREATE TABLE "planting_areas" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "width" integer, "length" integer, "device_id" integer);
CREATE TABLE "plants" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "device_id" integer, "planting_area_id" integer, "name" varchar, "img_url" varchar, "icon_url" varchar, "openfarm_slug" varchar, "x" varchar, "y" varchar, "planted_at" varchar);
CREATE TABLE "regimen_items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "time_offset" varchar, "schedule_id" integer, "regimen_id" integer, "sequence_id" integer);
CREATE TABLE "regimens" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "color" varchar, "name" varchar, "device_id" integer);
CREATE TABLE "schedules" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "sequence_id" integer, "device_id" integer, "start_time" datetime, "end_time" datetime, "next_time" datetime, "repeat" integer, "time_unit" varchar);
CREATE TABLE "sequences" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "schedule_id" integer, "device_id" integer, "regimen" varchar, "name" varchar, "color" varchar);
CREATE TABLE "steps" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "sequence_id" integer, "message_type" varchar, "position" integer, "command" text);
CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "device_id" integer, "name" varchar, "email" varchar DEFAULT '' NOT NULL, "encrypted_password" varchar DEFAULT '' NOT NULL, "reset_password_token" varchar, "reset_password_sent_at" datetime, "remember_created_at" datetime, "sign_in_count" integer DEFAULT 0 NOT NULL, "current_sign_in_at" datetime, "last_sign_in_at" datetime, "current_sign_in_ip" varchar, "last_sign_in_ip" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL);
CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email");
CREATE UNIQUE INDEX "index_users_on_reset_password_token" ON "users" ("reset_password_token");
INSERT INTO schema_migrations (version) VALUES ('20160820050202');

View File

@ -14,7 +14,7 @@ describe Api::DevicesController do
params = {user_id: user.id, name: 'Frank', uuid: '123', token: '321'}
post :create, params
resp = JSON.parse(response.body)
new_device = Device.find(resp['_id'])
new_device = Device.find(resp['id'])
user.reload
expect(user.device).to eq(new_device)
expect(response.status).to eq(200)
@ -27,7 +27,7 @@ describe Api::DevicesController do
post :create, params
user.reload
user2.reload
expect(user.device._id).to eq(user2.device._id)
expect(user.device.id).to eq(user2.device.id)
end
end
end

View File

@ -13,7 +13,7 @@ describe Api::DevicesController do
old_bot = user.device
delete :destroy, id: user.device.id, fromat: :json
user.reload
expect(user.device._id).not_to eq(old_bot._id)
expect(user.device.id).not_to eq(old_bot.id)
expect(response.status).to eq(204)
end
end

View File

@ -12,7 +12,7 @@ describe Api::DevicesController do
sign_in user
get :show, format: :json
device = user.device
id = JSON.parse(response.body)["_id"]
id = JSON.parse(response.body)["id"]
expect(Device.find(id)).to eq(device)
expect(response.status).to eq(200)
end

View File

@ -40,7 +40,7 @@ describe Api::DevicesController do
post :update, { name: 'Frank', uuid: bot.uuid, token: bot.token }
user.reload
user2.reload
expect(user.device._id).to eq(user2.device._id)
expect(user.device.id).to eq(user2.device.id)
end
end
end

View File

@ -9,7 +9,7 @@ describe Api::RegimensController do
it 'retrieves all regimina' do
sign_in user
old_count = Regimen.count
delete :destroy, { id: regimen._id.to_s }
delete :destroy, { id: regimen.id }
new_count = Regimen.count
expect(response.status).to eq(200)
expect(old_count).to be > new_count

View File

@ -6,17 +6,18 @@ describe Api::RegimensController do
describe '#index' do
let(:user) { FactoryGirl.create(:user) }
let!(:regimen) { FactoryGirl.create(:regimen, device: user.device) }
it 'retrieves all regimina' do
regimen = Regimen.create(device: user.device)
sign_in user
get :index
expect(response.status).to eq(200)
expect(json.count).to eq(1)
expect(json.first[:_id]).to eq(regimen._id.to_s)
expect(json.first[:id]).to eq(regimen.id)
end
it 'doesnt fetch other peoples regimens' do
regimen = Regimen.create(device: user.device)
other_person = FactoryGirl.create(:user)
sign_in other_person
get :index

View File

@ -8,7 +8,7 @@ describe Api::SchedulesController do
it 'makes a schedule' do
sign_in user
seq_id = FactoryGirl.create(:sequence)._id.to_s
seq_id = FactoryGirl.create(:sequence).id
input = { sequence_id: seq_id,
start_time: '2015-02-17T15:16:17.000Z',
end_time: '2099-02-17T18:19:20.000Z',

View File

@ -10,7 +10,7 @@ describe Api::SchedulesController do
sign_in user
schedule = FactoryGirl.create(:schedule, device: user.device)
before = Schedule.count
delete :destroy, id: schedule._id.to_s
delete :destroy, id: schedule.id
expect(response.status).to eq(200)
expect(before > Schedule.count).to be_truthy
@ -19,7 +19,7 @@ describe Api::SchedulesController do
it 'prevents unauthorized deletion' do
sign_in user
schedule = FactoryGirl.create(:schedule)
delete :destroy, id: schedule._id.to_s
delete :destroy, id: schedule.id
before = Schedule.count
expect(response.status).to eq(403)

View File

@ -9,15 +9,17 @@ describe Api::SchedulesController do
it 'lists all schedules for a user' do
sign_in user
schedules = FactoryGirl
.create_list(:schedule, 2, device: user.device)
.map(&:_id)
.map(&:to_s)
.sort
schedule_ids = schedules
.map(&:id)
.sort
get :index
binding.pry
expect(response.status).to eq(200)
expect(json.length).to eq(2)
expect(json.map{ |s| s[:_id] }.sort).to eq(schedules)
expect(json.map { |s| s[:id] }.sort).to eq(schedule_ids)
end
end
end

View File

@ -8,7 +8,7 @@ describe Api::SchedulesController do
it 'allows authorized modification' do
sign_in user
id = FactoryGirl.create(:schedule, device: user.device)._id.to_s
id = FactoryGirl.create(:schedule, device: user.device).id
input = { id: id, schedule: { repeat: 66 } }
patch :update, input
expect(response.status).to eq(200)
@ -16,7 +16,7 @@ describe Api::SchedulesController do
it 'prevents unauthorized modification' do
sign_in user
id = FactoryGirl.create(:schedule)._id.to_s
id = FactoryGirl.create(:schedule).id
input = { id: id, repeat: 66 }
patch :update, input
expect(response.status).to eq(403)

View File

@ -13,17 +13,17 @@ describe Api::SequencesController do
it 'destroys a sequence' do
sign_in user
input = { id: sequence._id.to_s }
input = { id: sequence.id }
delete :destroy, input
expect(response.status).to eq(200)
expect { sequence.reload }
.to(raise_error(Mongoid::Errors::DocumentNotFound))
.to(raise_error(ActiveRecord::RecordNotFound))
end
it 'doesnt destroy other peoples sequence' do
sign_in user
other_dudes = FactoryGirl.create(:sequence)
input = { id: other_dudes._id.to_s }
input = { id: other_dudes.id }
delete :destroy, input
expect(response.status).to eq(403)
end

View File

@ -13,12 +13,11 @@ describe Api::SequencesController do
sequences = FactoryGirl
.create_list(:sequence, 2, device: user.device)
.map(&:id)
.map(&:to_s)
.sort
get :index
expect(response.status).to eq(200)
expect(json.length).to eq(2)
expect(json.map{ |s| s[:_id] }.sort).to eq(sequences)
expect(json.map{ |s| s[:id] }.sort).to eq(sequences)
end
end
end

View File

@ -10,10 +10,10 @@ describe Api::SequencesController do
it 'shows sequence' do
sign_in user
id = FactoryGirl.create(:sequence, device: user.device)._id.to_s
id = FactoryGirl.create(:sequence, device: user.device).id
get :show, id: id
expect(response.status).to eq(200)
expect(json[:_id]).to eq(id)
expect(json[:id]).to eq(id)
end
end
end

View File

@ -11,7 +11,7 @@ describe Api::SequencesController do
it 'updates existing sequences' do
sign_in user
sequence = FactoryGirl.create(:sequence, device: user.device)
input = { id: sequence._id.to_s,
input = { id: sequence.id,
sequence: { name: "Scare Birds",
steps: [{ message_type: 'move_relative',
command: { action: 'MOVE RELATIVE',

View File

@ -11,7 +11,7 @@ describe Api::StepsController do
it 'creates a new step sequence' do
sign_in user
input = { sequence_id: sequence._id.to_s,
input = { sequence_id: sequence.id,
name: 'Scare Birds',
message_type: 'move_relative',
command: { action: 'MOVE RELATIVE',

View File

@ -15,8 +15,8 @@ describe Api::StepsController do
it 'destroys a step sequence' do
sign_in user
input = { sequence_id: sequence._id.to_s,
id: step._id.to_s }
input = { sequence_id: sequence.id,
id: step.id }
before = sequence.steps.count
delete :destroy, input
expect(response.status).to eq(200)
@ -25,19 +25,18 @@ describe Api::StepsController do
it 'handles 404 for step' do
sign_in user
input = { sequence_id: sequence._id.to_s,
input = { sequence_id: sequence.id,
id: '0000000000' }
delete :destroy, input
expect(response.status).to eq(404)
expect(response.body).to include("Can't find Step(s)")
expect(response.body).to include('0000000000')
expect(response.body).to include("Document not found.")
end
it 'cannot delete other peoples steps' do
other_guy = FactoryGirl.create(:user)
sign_in other_guy
input = { sequence_id: sequence._id.to_s,
id: step._id.to_s }
input = { sequence_id: sequence.id,
id: step.id }
unchanged = sequence.steps.count
delete :destroy, input
expect(response.status).to eq(403)

View File

@ -10,9 +10,9 @@ describe Api::StepsController do
it 'retrieves all steps for a sequence' do
sign_in user
get :index, sequence_id: sequence._id.to_s
get :index, sequence_id: sequence.id
expect(response.status).to eq(200)
expect(json[0][:_id]).to eq(sequence.steps[0]._id.to_s)
expect(json[0][:id]).to eq(sequence.steps[0].id)
end
end
end

View File

@ -8,12 +8,12 @@ describe Api::StepsController do
let(:user) { FactoryGirl.create :user }
it 'retrieves all steps for a sequence' do
id = sequence.steps.first._id.to_s
sequence_id = sequence._id.to_s
id = sequence.steps.first.id
sequence_id = sequence.id
sign_in user
get :show, sequence_id: sequence_id, id: id
expect(response.status).to eq(200)
expect(json[:_id]).to eq(id)
expect(json[:id]).to eq(id)
end
end
end

View File

@ -11,8 +11,8 @@ describe Api::StepsController do
it 'updates a step' do
sign_in user
params = { id: step._id.to_s,
sequence_id: sequence._id.to_s,
params = { id: step.id,
sequence_id: sequence.id,
step: { message_type: 'read_status' } }
patch :update, params
expect(response.status).to eq(200)

View File

@ -14,7 +14,7 @@ describe Api::UsersController do
name: "Frank" }
post :create, params
expect(User.count > original_count).to be_truthy
user = User.find json[:user][:_id]
user = User.find json[:user][:id]
expect(user.name).to eq("Frank")
expect(user.email).to eq("t@g.com")
expect(user.valid_password?('Password123')).to be_truthy

View File

@ -5,7 +5,7 @@ describe Schedule do
it 'indicates next_occurrence' do\
actual = schedule.calculate_next_occurence
expected = schedule.schedule.next_occurrence
expected = schedule.schedule_rules.next_occurrence
expect(actual).to eq(expected)
end
end

View File

@ -12,10 +12,10 @@ describe Regimens::Create do
regimen_items: [
{
time_offset: 129600000,
sequence_id: seq1._id.to_s
sequence_id: seq1.id
}, {
time_offset: 259200000,
sequence_id: seq2._id.to_s
sequence_id: seq2.id
}
]
}

View File

@ -20,7 +20,7 @@ describe Steps::Create do
expect(outcome.result.sequence).to eq(valid_params[:sequence])
cmd = outcome.result.command.deep_symbolize_keys
expect(cmd).to eq(valid_params[:command])
expect(sequence.steps.order_by(position: 1).last).to eq(outcome.result)
expect(sequence.steps.order(position: :asc).last).to eq(outcome.result)
end
it 'inserts new steps at a specified index' do

View File

@ -37,6 +37,8 @@ end
RSpec.configure do |config|
config.backtrace_exclusion_patterns = [/gems/]
config.include Helpers
config.infer_spec_type_from_file_location!
config.order = 'random'
@ -46,6 +48,9 @@ RSpec.configure do |config|
SmarfDoc.run!(request, response)
end
end
config.before(:suite) do
ActiveRecord::Base.subclasses.map(&:delete_all)
end
config.after(:suite) { SmarfDoc.finish! }
config.after do