Write a test for image attachment method, disable DJ in test suite.

pull/305/head
Rick Carlino 2017-01-11 10:07:34 -06:00
parent 82a2841064
commit 57e86ecfef
6 changed files with 16 additions and 8 deletions

View File

@ -17,11 +17,11 @@ class Image < ApplicationRecord
"image/jpeg",
"image/png",
"image/gif"]
def set_attachment_by_url(url)
# Image.new.from_url("http://i.imgur.com/OhLresv.png").save!
# Image.new.set_attachment_by_url("http://i.imgur.com/OhLresv.png").save!
self.attachment = open(url)
self.image_processed_at = Time.now
self.attachment_processed_at = Time.now
self
end
handle_asynchronously :set_attachment_by_url
end

View File

@ -1,5 +1,6 @@
FarmBot::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.active_job.queue_adapter = nil
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
@ -35,5 +36,5 @@ FarmBot::Application.configure do
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
config.log_level = :error
config.log_level = :error
end

View File

@ -2,7 +2,7 @@ class CreateImages < ActiveRecord::Migration[5.0]
def change
create_table :images do |t|
t.integer :device_id
t.datetime :image_processed_at
t.datetime :attachment_processed_at
t.timestamps
end

View File

@ -36,7 +36,7 @@ ActiveRecord::Schema.define(version: 20170111035209) do
create_table "images", force: :cascade do |t|
t.integer "device_id"
t.datetime "image_processed_at"
t.datetime "attachment_processed_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "attachment_file_name"

BIN
spec/fixture.jpg 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

View File

@ -4,7 +4,14 @@ describe Image do
let(:device) { FactoryGirl.create(:device) }
it 'adds URL attachments' do
image = Image.new
binding.pry
image = Image.create(device: device)
expect(image.attachment_processed_at).to be_nil
expect(image.attachment.exists?).to be_falsy
image.set_attachment_by_url("http://i.imgur.com/OhLresv.png")
image.save!
expect(image.attachment.exists?).to be_truthy
expect(image.attachment_processed_at).to be_truthy
end
end