2017-02-07 09:47:34 -07:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Api::PointsController do
|
|
|
|
include Devise::Test::ControllerHelpers
|
|
|
|
describe '#index' do
|
|
|
|
let(:device) { FactoryGirl.create(:device) }
|
|
|
|
let(:user) { FactoryGirl.create(:user, device: device) }
|
|
|
|
|
|
|
|
it 'lists points' do
|
|
|
|
sign_in user
|
|
|
|
FactoryGirl.create_list(:point, 3, device: device)
|
|
|
|
get :index
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json.length).to eq(3)
|
|
|
|
expect(json.first.keys).to include(:x)
|
|
|
|
end
|
2017-05-10 12:42:24 -06:00
|
|
|
it 'lists all plants' do
|
|
|
|
Point.destroy_all
|
|
|
|
plants = 3.times do |num|
|
|
|
|
Point.create!(x: num,
|
|
|
|
y: num,
|
|
|
|
z: num,
|
|
|
|
radius: 50,
|
|
|
|
name: "Cabbage #{num}",
|
|
|
|
device: user.device,
|
|
|
|
pointer: Plant.new(openfarm_slug: "cabbage"))
|
|
|
|
end
|
|
|
|
sign_in user
|
|
|
|
get :index
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json.length).to eq(3)
|
|
|
|
end
|
|
|
|
it 'lists all tool slots' do
|
|
|
|
Point.destroy_all
|
|
|
|
sign_in user
|
|
|
|
ts = Point.create(x: 0,
|
|
|
|
y: 0,
|
|
|
|
z: 0,
|
|
|
|
radius: 50,
|
|
|
|
name: "My TS",
|
|
|
|
device: user.device,
|
2017-05-10 13:37:35 -06:00
|
|
|
pointer: ToolSlot.new)
|
2017-05-10 12:42:24 -06:00
|
|
|
get :index
|
2017-05-10 14:20:14 -06:00
|
|
|
binding.pry
|
2017-05-10 12:42:24 -06:00
|
|
|
expect(json.first[:id]).to eq(ts.id)
|
|
|
|
expect(json.first[:name]).to eq(ts.point.name)
|
|
|
|
end
|
2017-02-07 09:47:34 -07:00
|
|
|
end
|
|
|
|
end
|