-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
# Description of Places Class | ||
class Local < ApplicationRecord | ||
has_many :favorite_locals, dependent: :destroy | ||
has_many :local_ratings | ||
validates :name, presence: true, length: { minimum: 2 } | ||
validates :RatingRate, presence: true | ||
|
||
def self.find_by_name(params) | ||
Local.where('upper(name) like ?', "%#{params.upcase}%") | ||
end | ||
|
||
def self.find_local_ratings(local_id) | ||
Local.find(local_id).local_ratings | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Description of Local Rating Class | ||
class LocalRating < ApplicationRecord | ||
belongs_to :local | ||
validates_associated :local | ||
validates :value, presence: true | ||
validates :value, numericality: true | ||
validates_numericality_of :value, less_than_or_equal_to: 5 | ||
validates_numericality_of :value, greater_than_or_equal_to: 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
indicaAi/db/migrate/20180917224258_remove_rating_rate_from_locals.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class RemoveRatingRateFromLocals < ActiveRecord::Migration[5.1] | ||
def change | ||
remove_column :locals, :RatingRate, :float | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
indicaAi/db/migrate/20180917225656_create_local_ratings.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateLocalRatings < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :local_ratings do |t| | ||
t.integer :value | ||
t.references :local, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe LocalsController, type: :controller do | ||
it { should route(:get, '/locals').to(action: :index) } | ||
it 'should return a JSON object' do | ||
get :index, format: :JSON | ||
expect(response).to be_success | ||
end | ||
|
||
context 'GET #search_locals' do | ||
let!(:local) { create(:local, name: 'Xoxo') } | ||
it 'should route locals/name/x to the corresponding action' do | ||
should route(:get, '/locals/name/x').to(action: :search_locals, name: 'x') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
FactoryBot.define do | ||
factory :local do | ||
name { Faker::Nation.capital_city } | ||
RatingRate { Faker::Number.decimal(2) } | ||
# generates locations from the tv serie 'Friends' :D | ||
name { Faker::Friends.location } | ||
# generates quotations from 'Friends' | ||
description { Faker::Friends.quote } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FactoryBot.define do | ||
factory :local_rating do | ||
value { Faker::Number.between(0, 5) } | ||
local { create(:local) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe LocalRating, type: :model do | ||
it { should validate_numericality_of(:value).is_greater_than_or_equal_to(0) } | ||
|
||
describe 'testing validations' do | ||
context 'ratings validation tests' do | ||
let!(:note) { create(:local_rating) } | ||
it 'should return a integer value' do | ||
assert note.value.class == Integer | ||
end | ||
end | ||
it 'should return a integer though a float was given' do | ||
note2 = LocalRating.new | ||
note2.value = 3.4 | ||
assert note2.value == 3 | ||
end | ||
|
||
it { should belong_to(:local) } | ||
|
||
it { should validate_presence_of(:value) } | ||
|
||
it { should validate_numericality_of(:value) } | ||
|
||
it { should validate_numericality_of(:value).is_less_than_or_equal_to(5) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe Local, type: :model do | ||
let!(:local) { create(:local) } | ||
let!(:favorite_locals) { create_list(:favorite_local, 10, local: local) } | ||
it { should have_many(:favorite_locals).dependent(:destroy) } | ||
context 'Validate of UserIdentifier' do | ||
it { should validate_presence_of(:name) } | ||
it 'local valid' do | ||
local = create(:local) | ||
expect(local.valid?).to be_truthy | ||
end | ||
it { should validate_presence_of(:name) } | ||
|
||
it 'local invalid' do | ||
local.name = '' | ||
expect(local.valid?).to be_falsey | ||
end | ||
it 'Testing Search By Name - Should return similar names to params' do | ||
local = create(:local) | ||
name = local.name | ||
result = Local.find_by_name(name) | ||
assert result.first, local | ||
end | ||
|
||
it 'Testing Find Local Ratings - Should return rating associated to parms' do | ||
local = create(:local) | ||
nota = create(:local_rating, local: local) | ||
|
||
id = local.id | ||
result = Local.find_local_ratings(id) | ||
assert result.first, nota | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters