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 "rack-attack"
|
||||
gem "paperclip", "~> 5.0.0"
|
||||
gem 'delayed_job_active_record'
|
||||
|
||||
group :development, :test do
|
||||
gem "sqlite3"
|
||||
|
|
|
@ -57,6 +57,11 @@ GEM
|
|||
concurrent-ruby (1.0.2)
|
||||
daemons (1.2.4)
|
||||
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)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
|
@ -211,6 +216,7 @@ PLATFORMS
|
|||
DEPENDENCIES
|
||||
active_model_serializers (~> 0.8.3)
|
||||
database_cleaner
|
||||
delayed_job_active_record
|
||||
devise
|
||||
factory_girl_rails
|
||||
faker
|
||||
|
|
|
@ -10,6 +10,7 @@ class Device < ActiveRecord::Base
|
|||
has_many :peripherals, dependent: :destroy
|
||||
has_many :tool_bays, dependent: :destroy
|
||||
has_many :tools, dependent: :destroy
|
||||
has_many :images, dependent: :destroy
|
||||
has_one :planting_area, dependent: :destroy
|
||||
validates :name, uniqueness: true
|
||||
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
require "open-uri"
|
||||
|
||||
class Image < ApplicationRecord
|
||||
belongs_to :device
|
||||
validates :device, presence: true
|
||||
|
||||
has_attached_file :attachment,
|
||||
# default_url: "/images/:style/missing.png",
|
||||
styles: { x1280: "1280x1280>",
|
||||
|
@ -7,8 +12,16 @@ class Image < ApplicationRecord
|
|||
x160: "160x160>",
|
||||
x80: "80x80>" },
|
||||
size: { in: 0..5.megabytes } # Worst case scenario for 1280x1280 BMP.
|
||||
validates_attachment_content_type :attachment, content_type: /\Aimage\/.*\z/
|
||||
validates_attachment_file_name :attachment, matches: [/png\z/,
|
||||
/jpe?g\z/,
|
||||
/bmp\z/]
|
||||
validates_attachment_content_type :attachment,
|
||||
content_type: ["image/jpg",
|
||||
"image/jpeg",
|
||||
"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
|
||||
|
|
|
@ -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
|
||||
class Application < Rails::Application
|
||||
# Settings in config/environments/* take precedence over those specified
|
||||
# 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.active_job.queue_adapter = :delayed_job
|
||||
config.action_dispatch.perform_deep_munge = false
|
||||
I18n.enforce_available_locales = false
|
||||
config.generators do |g|
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
class CreateImages < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
create_table :images do |t|
|
||||
t.integer :device_id
|
||||
t.datetime :image_processed_at
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :images, :device_id
|
||||
add_attachment :images, :attachment
|
||||
end
|
||||
end
|
||||
|
|
|
@ -35,12 +35,15 @@ ActiveRecord::Schema.define(version: 20170111035209) do
|
|||
end
|
||||
|
||||
create_table "images", force: :cascade do |t|
|
||||
t.integer "device_id"
|
||||
t.datetime "image_processed_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "attachment_file_name"
|
||||
t.string "attachment_content_type"
|
||||
t.integer "attachment_file_size"
|
||||
t.datetime "attachment_updated_at"
|
||||
t.index ["device_id"], name: "index_images_on_device_id"
|
||||
end
|
||||
|
||||
create_table "logs", force: :cascade do |t|
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Image, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe Image do
|
||||
let(:device) { FactoryGirl.create(:device) }
|
||||
|
||||
it 'adds URL attachments' do
|
||||
image = Image.new
|
||||
binding.pry
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue