Add more fields, validations to image and start writing model tests.
parent
93aeee43ec
commit
82a2841064
1
Gemfile
1
Gemfile
|
@ -15,6 +15,7 @@ gem "database_cleaner"
|
||||||
gem "rollbar"
|
gem "rollbar"
|
||||||
gem "rack-attack"
|
gem "rack-attack"
|
||||||
gem "paperclip", "~> 5.0.0"
|
gem "paperclip", "~> 5.0.0"
|
||||||
|
gem 'delayed_job_active_record'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem "sqlite3"
|
gem "sqlite3"
|
||||||
|
|
|
@ -57,6 +57,11 @@ GEM
|
||||||
concurrent-ruby (1.0.2)
|
concurrent-ruby (1.0.2)
|
||||||
daemons (1.2.4)
|
daemons (1.2.4)
|
||||||
database_cleaner (1.5.3)
|
database_cleaner (1.5.3)
|
||||||
|
delayed_job (4.1.2)
|
||||||
|
activesupport (>= 3.0, < 5.1)
|
||||||
|
delayed_job_active_record (4.1.1)
|
||||||
|
activerecord (>= 3.0, < 5.1)
|
||||||
|
delayed_job (>= 3.0, < 5)
|
||||||
devise (4.2.0)
|
devise (4.2.0)
|
||||||
bcrypt (~> 3.0)
|
bcrypt (~> 3.0)
|
||||||
orm_adapter (~> 0.1)
|
orm_adapter (~> 0.1)
|
||||||
|
@ -211,6 +216,7 @@ PLATFORMS
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
active_model_serializers (~> 0.8.3)
|
active_model_serializers (~> 0.8.3)
|
||||||
database_cleaner
|
database_cleaner
|
||||||
|
delayed_job_active_record
|
||||||
devise
|
devise
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
faker
|
faker
|
||||||
|
|
|
@ -10,6 +10,7 @@ class Device < ActiveRecord::Base
|
||||||
has_many :peripherals, dependent: :destroy
|
has_many :peripherals, dependent: :destroy
|
||||||
has_many :tool_bays, dependent: :destroy
|
has_many :tool_bays, dependent: :destroy
|
||||||
has_many :tools, dependent: :destroy
|
has_many :tools, dependent: :destroy
|
||||||
|
has_many :images, dependent: :destroy
|
||||||
has_one :planting_area, dependent: :destroy
|
has_one :planting_area, dependent: :destroy
|
||||||
validates :name, uniqueness: true
|
validates :name, uniqueness: true
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
|
require "open-uri"
|
||||||
|
|
||||||
class Image < ApplicationRecord
|
class Image < ApplicationRecord
|
||||||
|
belongs_to :device
|
||||||
|
validates :device, presence: true
|
||||||
|
|
||||||
has_attached_file :attachment,
|
has_attached_file :attachment,
|
||||||
# default_url: "/images/:style/missing.png",
|
# default_url: "/images/:style/missing.png",
|
||||||
styles: { x1280: "1280x1280>",
|
styles: { x1280: "1280x1280>",
|
||||||
|
@ -7,8 +12,16 @@ class Image < ApplicationRecord
|
||||||
x160: "160x160>",
|
x160: "160x160>",
|
||||||
x80: "80x80>" },
|
x80: "80x80>" },
|
||||||
size: { in: 0..5.megabytes } # Worst case scenario for 1280x1280 BMP.
|
size: { in: 0..5.megabytes } # Worst case scenario for 1280x1280 BMP.
|
||||||
validates_attachment_content_type :attachment, content_type: /\Aimage\/.*\z/
|
validates_attachment_content_type :attachment,
|
||||||
validates_attachment_file_name :attachment, matches: [/png\z/,
|
content_type: ["image/jpg",
|
||||||
/jpe?g\z/,
|
"image/jpeg",
|
||||||
/bmp\z/]
|
"image/png",
|
||||||
|
"image/gif"]
|
||||||
|
def set_attachment_by_url(url)
|
||||||
|
# Image.new.from_url("http://i.imgur.com/OhLresv.png").save!
|
||||||
|
self.attachment = open(url)
|
||||||
|
self.image_processed_at = Time.now
|
||||||
|
self
|
||||||
|
end
|
||||||
|
handle_asynchronously :set_attachment_by_url
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
|
||||||
|
require 'delayed/command'
|
||||||
|
Delayed::Command.new(ARGV).daemonize
|
|
@ -7,18 +7,7 @@ Bundler.require(:default, Rails.env)
|
||||||
|
|
||||||
module FarmBot
|
module FarmBot
|
||||||
class Application < Rails::Application
|
class Application < Rails::Application
|
||||||
# Settings in config/environments/* take precedence over those specified
|
config.active_job.queue_adapter = :delayed_job
|
||||||
# here. Application configuration should go into files in
|
|
||||||
# config/initializers
|
|
||||||
# -- all .rb files in that directory are automatically loaded.
|
|
||||||
|
|
||||||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
|
||||||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
|
||||||
# config.time_zone = 'Central Time (US & Canada)'
|
|
||||||
|
|
||||||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
|
||||||
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
|
||||||
# config.i18n.default_locale = :de
|
|
||||||
config.action_dispatch.perform_deep_munge = false
|
config.action_dispatch.perform_deep_munge = false
|
||||||
I18n.enforce_available_locales = false
|
I18n.enforce_available_locales = false
|
||||||
config.generators do |g|
|
config.generators do |g|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
class CreateImages < ActiveRecord::Migration[5.0]
|
class CreateImages < ActiveRecord::Migration[5.0]
|
||||||
def change
|
def change
|
||||||
create_table :images do |t|
|
create_table :images do |t|
|
||||||
|
t.integer :device_id
|
||||||
|
t.datetime :image_processed_at
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index :images, :device_id
|
||||||
add_attachment :images, :attachment
|
add_attachment :images, :attachment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,12 +35,15 @@ ActiveRecord::Schema.define(version: 20170111035209) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "images", force: :cascade do |t|
|
create_table "images", force: :cascade do |t|
|
||||||
|
t.integer "device_id"
|
||||||
|
t.datetime "image_processed_at"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "attachment_file_name"
|
t.string "attachment_file_name"
|
||||||
t.string "attachment_content_type"
|
t.string "attachment_content_type"
|
||||||
t.integer "attachment_file_size"
|
t.integer "attachment_file_size"
|
||||||
t.datetime "attachment_updated_at"
|
t.datetime "attachment_updated_at"
|
||||||
|
t.index ["device_id"], name: "index_images_on_device_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "logs", force: :cascade do |t|
|
create_table "logs", force: :cascade do |t|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
RSpec.describe Image, type: :model do
|
describe Image do
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
let(:device) { FactoryGirl.create(:device) }
|
||||||
|
|
||||||
|
it 'adds URL attachments' do
|
||||||
|
image = Image.new
|
||||||
|
binding.pry
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue