Skip to content

Commit

Permalink
#264 - Finishing Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zarbielli committed Nov 3, 2018
1 parent 360e658 commit 2425e53
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 20 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ WORKDIR /indicaAi
COPY ./indicaAi /indicaAi

RUN bundle install
RUN rake db:migrate

3 changes: 0 additions & 3 deletions heroku.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ build:
web: Dockerfile
config:
RAILS_ENV: production
release:
command:
- rake db:migrate
run:
web: puma
6 changes: 6 additions & 0 deletions indicaAi/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ git_source(:github) do |repo_name|
"https://github.com/#{repo_name}.git"
end

gem 'i18n', '~> 1.1', '>= 1.1.1'
# Upload files encoded as base64 strings directly to carrierwave
gem 'carrierwave'
gem 'carrierwave-base64', '~> 2.7'
# Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
gem 'mini_magick', '~> 4.9', '>= 4.9.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'
# Use postgresql as the database for Active Record
Expand Down
29 changes: 22 additions & 7 deletions indicaAi/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ GEM
ast (2.4.0)
builder (3.2.3)
byebug (10.0.2)
carrierwave (1.2.3)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
carrierwave-base64 (2.7.0)
carrierwave (>= 0.8.0)
mime-types (~> 3.0)
concurrent-ruby (1.0.5)
coveralls (0.8.22)
json (>= 1.8, < 3)
Expand All @@ -64,7 +71,7 @@ GEM
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.1.0)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.1)
json (2.1.0)
Expand All @@ -75,14 +82,18 @@ GEM
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
method_source (0.9.0)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
mini_magick (4.9.2)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3)
nio4r (2.3.1)
nokogiri (1.8.4)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
parallel (1.12.1)
parser (2.5.1.2)
Expand Down Expand Up @@ -127,13 +138,13 @@ GEM
ffi (>= 0.5.0, < 2)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
rspec-expectations (3.8.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-rails (3.8.0)
rspec-rails (3.8.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
Expand Down Expand Up @@ -175,7 +186,7 @@ GEM
tins (~> 1.0)
thor (0.19.4)
thread_safe (0.3.6)
tins (1.16.3)
tins (1.17.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
Expand All @@ -188,11 +199,15 @@ PLATFORMS

DEPENDENCIES
byebug
carrierwave
carrierwave-base64 (~> 2.7)
coveralls (~> 0.8.22)
database_cleaner (~> 1.7)
factory_bot_rails (~> 4.11, >= 4.11.1)
faker (~> 1.9, >= 1.9.1)
i18n (~> 1.1, >= 1.1.1)
listen (>= 3.0.5, < 3.2)
mini_magick (~> 4.9, >= 4.9.2)
pg (>= 0.18, < 2.0)
puma (~> 3.7)
rails (~> 5.1.6)
Expand All @@ -205,4 +220,4 @@ DEPENDENCIES
tzinfo-data

BUNDLED WITH
1.16.4
1.16.6
21 changes: 21 additions & 0 deletions indicaAi/app/controllers/local_images_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Local Images Controller
class LocalImagesController < ApplicationController
def receive_image
local = Local.find(params[:id])
if local.present?
images = params[:image]
images.each do |image|
LocalImage.create(image: image, local_id: params[:id])
end
response_success('SUCCESS', 'Images saved', 200)
else
response_error('ERROR', 'Place not found', 422)
end
end

private

def local_images_params
params.require(:local_id).permit(images: [])
end
end
2 changes: 1 addition & 1 deletion indicaAi/app/controllers/locals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create
create_relationship_category_and_local(params)
# create tables in bd with opening hours
create_opening_hours
result << @local.as_json(methods: %i[opening_hours categories])
result << @local.as_json(methods: %i[opening_hours categories local_images])
response_success('SUCCESS', 'Saved Local', result, 200)
else
response_error('ERROR', 'Local not saved', 422)
Expand Down
4 changes: 0 additions & 4 deletions indicaAi/app/models/image_local.rb

This file was deleted.

1 change: 1 addition & 0 deletions indicaAi/app/models/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Local < ApplicationRecord
has_many :opening_hours
has_many :category_and_locals
has_many :categories, through: :category_and_locals
has_many :local_images
validates :name, presence: true, length: { minimum: 2 }
validates :latitude, presence: true, numericality: {
greater_than_or_equal: 0, less_than_or_equal: 100
Expand Down
5 changes: 5 additions & 0 deletions indicaAi/app/models/local_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Model of LocalImage
class LocalImage < ApplicationRecord
belongs_to :local
mount_uploaders :images, ImageUploader
end
1 change: 1 addition & 0 deletions indicaAi/config/environment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Load the Rails application.
require_relative 'application'
require 'carrierwave/orm/activerecord'

# Initialize the Rails application.
Rails.application.initialize!
1 change: 1 addition & 0 deletions indicaAi/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
post '/favorites', to: 'favorite_locals#create', :defaults => { :format => 'json' }
post '/locals', to: 'locals#create', :defaults => { :format => 'json' }
post '/local_ratings', to: 'local_ratings#rating_a_place'
post '/local/:id/images/', to: 'local_images#receive_image'

# Patch Requests
put '/favorites/:id', to: 'favorite_locals#update', :defaults => { :format => 'json' }
Expand Down
9 changes: 9 additions & 0 deletions indicaAi/db/migrate/20181027162156_create_local_images.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateLocalImages < ActiveRecord::Migration[5.1]
def change
create_table :local_images do |t|
t.text :image
t.references :local, foreign_key: true
t.timestamps
end
end
end
11 changes: 10 additions & 1 deletion indicaAi/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20181024041749) do
ActiveRecord::Schema.define(version: 20181027162156) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -47,6 +47,14 @@
t.index ["local_id"], name: "index_image_locals_on_local_id"
end

create_table "local_images", force: :cascade do |t|
t.text "image"
t.bigint "local_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["local_id"], name: "index_local_images_on_local_id"
end

create_table "local_ratings", force: :cascade do |t|
t.integer "value"
t.bigint "local_id"
Expand Down Expand Up @@ -89,6 +97,7 @@
add_foreign_key "favorite_locals", "locals"
add_foreign_key "favorite_locals", "user_identifiers"
add_foreign_key "image_locals", "locals"
add_foreign_key "local_images", "locals"
add_foreign_key "local_ratings", "locals"
add_foreign_key "local_ratings", "user_identifiers"
end
27 changes: 27 additions & 0 deletions indicaAi/spec/controllers/local_images_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'rails_helper'

RSpec.describe LocalImagesController, type: :controller do
let!(:local) { create(:local) }
images = [Faker::ChuckNorris.fact, Faker::ChuckNorris.fact]
let!(:valid_params) do
{
id: local.id,
image: images
}
end
describe 'POST #recive_image' do
it 'Should return sucess, Image Saved' do
post :receive_image, params: valid_params
expect(response).to be_success
end
end

describe 'POST #recive_image' do
it 'Should return ERROR, Image not saved' do
# local_id invalid
valid_params['id'] = 'hi'
post :receive_image, params: valid_params
expect(response).to have_http_status(404)
end
end
end
4 changes: 0 additions & 4 deletions indicaAi/spec/models/image_local_spec.rb

This file was deleted.

7 changes: 7 additions & 0 deletions indicaAi/spec/models/local_image_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rails_helper'

RSpec.describe LocalImage, type: :model do
describe 'validations' do
it { should belong_to(:local) }
end
end

0 comments on commit 2425e53

Please sign in to comment.