[UNSTABLE] RSpec tests pass when renaming `last_seen` to `last_saw_api`.

pull/481/head
Rick Carlino 2017-10-03 10:03:06 -05:00
parent 3ee7f909bb
commit d5a2a604a8
10 changed files with 31 additions and 21 deletions

View File

@ -166,11 +166,11 @@ private
yield if pretty_ua.include?("FARMBOTOS")
end
# Devices have a `last_seen` field to assist users with debugging.
# Devices have a `last_saw_api` field to assist users with debugging.
# We update this column every time an FBOS device talks to the API.
def mark_as_seen(entity = (current_user && current_user.device))
when_farmbot_os do
entity.update_attributes(last_seen: Time.now) if entity
entity.update_attributes(last_saw_api: Time.now) if entity
end
end
end

View File

@ -1,3 +1,11 @@
class DeviceSerializer < ActiveModel::Serializer
attributes :id, :name, :webcam_url, :timezone, :last_seen
attributes :id, :name, :webcam_url, :timezone, :last_saw_api, :last_saw_mq,
:last_seen
def last_seen
# TODO: Remove this by December 2017.
# This is a legacy attribute that needs to go away, but will cause
# crashes on legacy versions of FBOS.
object.last_saw_api
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170918173928) do
ActiveRecord::Schema.define(version: 20171003144428) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -37,7 +37,8 @@ ActiveRecord::Schema.define(version: 20170918173928) do
t.integer "max_log_count", default: 100
t.integer "max_images_count", default: 100
t.string "timezone", limit: 280
t.datetime "last_seen"
t.datetime "last_saw_api"
t.datetime "last_saw_mq"
t.index ["timezone"], name: "index_devices_on_timezone"
end

View File

@ -52,7 +52,7 @@ describe Api::PointsController do
end
it "handles outdated FBOS" do
old_last_seen = user.device.last_seen
old_last_saw_api = user.device.last_saw_api
ua = "FARMBOTOS/1.1.1 (RPI3) RPI3 (1.1.1)"
allow(request).to receive(:user_agent).and_return(ua)
request.env["HTTP_USER_AGENT"] = ua
@ -64,16 +64,16 @@ describe Api::PointsController do
end
it "marks device as seen when they download points" do
old_last_seen = user.device.last_seen
old_last_saw_api = user.device.last_saw_api
ua = "FarmbotOS/5.0.2 (host) host ()"
allow(request).to receive(:user_agent).and_return(ua)
request.env["HTTP_USER_AGENT"] = ua
request.headers["Authorization"] = "bearer #{auth_token}"
FactoryGirl.create_list(:point, 1, device: device)
get :index
new_last_seen = user.device.reload.last_seen
new_last_saw_api = user.device.reload.last_saw_api
expect(response.status).to eq(200)
expect(new_last_seen).not_to eq(old_last_seen)
expect(new_last_saw_api).not_to eq(old_last_saw_api)
end
end
end

View File

@ -21,22 +21,22 @@ describe Api::TokensController do
expect(json[:error]).to include(err_msg)
end
it 'does not bump last_seen if it is not a bot' do
it 'does not bump last_saw_api if it is not a bot' do
payload = {user: {email: user.email, password: "password"}}
before = user.device.last_seen
before = user.device.last_saw_api
post :create, params: payload
after = user.device.reload.last_seen
after = user.device.reload.last_saw_api
expect(before).to eq(after)
end
it 'bumps last_seen when it is a bot' do
it 'bumps last_saw_api when it is a bot' do
ua = "FARMBOTOS/99.99.99 (RPI3) RPI3 (1.1.1)"
allow(request).to receive(:user_agent).and_return(ua)
request.env["HTTP_USER_AGENT"] = ua
payload = {user: {email: user.email, password: "password"}}
before = user.device.last_seen || Time.now
before = user.device.last_saw_api || Time.now
post :create, params: payload
after = user.device.reload.last_seen
after = user.device.reload.last_saw_api
expect(after).to be
expect(after).to be > before
end

View File

@ -25,7 +25,7 @@ describe("refresh()", () => {
"id": 6,
"name": "summer-pond-726",
"timezone": "America/Chicago",
"last_seen": "2017-08-30T20:42:35.854Z"
"last_saw_api": "2017-08-30T20:42:35.854Z"
},
};

View File

@ -5,7 +5,7 @@ jest.mock("axios", () => ({
"id": 6,
"name": "New Device From Server",
"timezone": "America/Chicago",
"last_seen": "2017-08-30T20:42:35.854Z"
"last_saw_api": "2017-08-30T20:42:35.854Z"
}
})
}
@ -32,7 +32,7 @@ describe("successful refresh()", () => {
"id": 6,
"name": "summer-pond-726",
"timezone": "America/Chicago",
"last_seen": "2017-08-30T20:42:35.854Z"
"last_saw_api": "2017-08-30T20:42:35.854Z"
},
};

View File

@ -10,7 +10,7 @@ interface LastSeenProps {
}
export class LastSeen extends React.Component<LastSeenProps, {}> {
get lastSeen() { return this.props.device.body.last_seen; }
get lastSeen() { return this.props.device.body.last_saw_api; }
show = (): string => {
if (this.props.device.specialStatus) {
return t("Loading...");

View File

@ -21,7 +21,7 @@ export class Devices extends React.Component<Props, {}> {
/** A record of all the things we know about connectivity right now. */
get flags(): Record<DiagnosisName, StatusRowProps> {
const mqttConnected = this.props.bot.connectedToMQTT;
const lastSeen = this.props.deviceAccount.body.last_seen;
const lastSeen = this.props.deviceAccount.body.last_saw_api;
const timestamp = this.props.bot.hardware.user_env["LAST_CLIENT_CONNECTED"];
const fwVersion = this.props.bot.hardware
.informational_settings.firmware_version;

View File

@ -35,7 +35,8 @@ export interface DeviceAccountSettings {
id: number;
name: string;
timezone?: string | undefined;
last_seen?: string | undefined;
last_saw_api?: string | undefined;
last_saw_mq?: string | undefined;
}
export interface BotState {