Skip to content

Commit

Permalink
ImageGallery model
Browse files Browse the repository at this point in the history
We can create an ImageGallery with its images, so we then link it
with the fields

See #869
  • Loading branch information
matiasgarciaisaia committed May 29, 2017
1 parent 90b9edb commit fd87425
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/models/image_gallery.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ImageGallery < ActiveRecord::Base
belongs_to :site
belongs_to :field
mount_uploaders :images, ImageGalleryUploader
end
14 changes: 14 additions & 0 deletions app/uploaders/image_gallery_uploader.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions db/migrate/20170524230256_create_image_galleries.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions spec/controllers/collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file added spec/fixtures/tracking_food.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions spec/requests/image_gallery_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fd87425

Please sign in to comment.