diff --git a/app/models/image_gallery.rb b/app/models/image_gallery.rb new file mode 100644 index 000000000..4d79e35ec --- /dev/null +++ b/app/models/image_gallery.rb @@ -0,0 +1,5 @@ +class ImageGallery < ActiveRecord::Base + belongs_to :site + belongs_to :field + mount_uploaders :images, ImageGalleryUploader +end diff --git a/app/uploaders/image_gallery_uploader.rb b/app/uploaders/image_gallery_uploader.rb new file mode 100644 index 000000000..ed2b0021f --- /dev/null +++ b/app/uploaders/image_gallery_uploader.rb @@ -0,0 +1,14 @@ +# encoding: utf-8 +class ImageGalleryUploader < CarrierWave::Uploader::Base + storage :file + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + def full_filename(filename) + "#{SecureRandom.uuid}-#{filename}" + end +end diff --git a/db/migrate/20170524230256_create_image_galleries.rb b/db/migrate/20170524230256_create_image_galleries.rb new file mode 100644 index 000000000..842a61dd7 --- /dev/null +++ b/db/migrate/20170524230256_create_image_galleries.rb @@ -0,0 +1,9 @@ +class CreateImageGalleries < ActiveRecord::Migration + def change + create_table :image_galleries do |t| + t.integer :site_id + t.integer :field_id + t.text :images + end + end +end diff --git a/db/schema.rb b/db/schema.rb index e0c12921e..8e01599b7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170523182508) do +ActiveRecord::Schema.define(version: 20170524230256) do create_table "activities", force: true do |t| t.integer "user_id" @@ -111,6 +111,12 @@ t.datetime "updated_at", null: false end + create_table "image_galleries", force: true do |t| + t.integer "site_id" + t.integer "field_id" + t.text "images" + end + create_table "import_jobs", force: true do |t| t.string "status" t.string "original_filename" diff --git a/spec/controllers/collections_controller_spec.rb b/spec/controllers/collections_controller_spec.rb index aefba5bf1..671aab875 100644 --- a/spec/controllers/collections_controller_spec.rb +++ b/spec/controllers/collections_controller_spec.rb @@ -358,4 +358,10 @@ def expect_redirect_to_login(response) expect(sites.first['properties'][numeric.es_code]).to eq(25) end + it "uploads a logo" do + file = fixture_file_upload('tracking_food.jpg', 'image/jpeg') + post :upload_logo, logo: file + response.should be_success + end + end diff --git a/spec/fixtures/tracking_food.jpg b/spec/fixtures/tracking_food.jpg new file mode 100644 index 000000000..65072ad8e Binary files /dev/null and b/spec/fixtures/tracking_food.jpg differ diff --git a/spec/requests/image_gallery_spec.rb b/spec/requests/image_gallery_spec.rb new file mode 100644 index 000000000..b1b120ad3 --- /dev/null +++ b/spec/requests/image_gallery_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe "Image Gallery" do + it "uploads multiple logos" do + file = File.open('spec/fixtures/tracking_food.jpg') + file2 = File.open('spec/fixtures/tracking_food.jpg') + instance = ImageGallery.new + instance.images = [file, file2] + instance.save! + instance.images.count.should eq(2) + instance.images.each do |image| + get image.url + response.should be_success + end + end + +end