-
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
13 changed files
with
122 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Local Ratings Controller | ||
class LocalRatingsController < ApplicationController | ||
# POST /local_rating/:local_name/:user_id/:rate | ||
def rating_a_place | ||
@rating = LocalRating.new(local_rating_params) | ||
if @rating.save | ||
render json: { status: :ok } | ||
else | ||
render json: { status: :error } | ||
end | ||
end | ||
|
||
private | ||
|
||
def local_rating_params | ||
{ | ||
local_id: params[:local_id], | ||
user_identifier_id: params[:user_identifier_id], | ||
value: params[:value] | ||
} | ||
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
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,17 @@ | ||
# Description of Local Rating Class | ||
class LocalRating < ApplicationRecord | ||
# Validations | ||
belongs_to :local | ||
validates_associated :local | ||
belongs_to :user_identifier | ||
validates_uniqueness_of :user_identifier, scope: :local_id | ||
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 | ||
validates :value, numericality: { | ||
only_integer: true, | ||
less_than_or_equal_to: 5, | ||
greater_than_or_equal_to: 0 | ||
} | ||
|
||
def self.find_local_rating(_params) | ||
LocalRating.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
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
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 @@ | ||
class CreateUserRates < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :user_rates do |t| | ||
t.integer :rating | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class LocalRating < ActiveRecord::Migration[5.1] | ||
def change | ||
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,4 @@ | ||
class Local < ActiveRecord::Migration[5.1] | ||
def change | ||
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,4 @@ | ||
class UserIdentifier < ActiveRecord::Migration[5.1] | ||
def change | ||
end | ||
end |
23 changes: 23 additions & 0 deletions
23
indicaAi/spec/controllers/local_ratings_controller_spec.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,23 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe LocalRatingsController, type: :controller do | ||
let!(:user_test) { create(:user_identifier) } | ||
let!(:local_test) { create(:local) } | ||
let!(:valid_params) do | ||
{ | ||
local_id: local_test.id, | ||
user_identifier_id: user_test.id, | ||
value: Faker::Number.between(0, 5) | ||
} | ||
end | ||
describe 'POST rating_a_place' do | ||
it 'should create a LocalRatingsController' do | ||
post :rating_a_place, params: valid_params | ||
expect(response).to be_success | ||
expect(assigns(:rating)).to have_attributes(valid_params) | ||
expect(assigns(:rating)).to be_persisted | ||
expect(assigns(:rating)).to be_a(LocalRating) | ||
expect(assigns(:rating)).not_to eq(nil) | ||
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,7 @@ | ||
FactoryBot.define do | ||
factory :local_rating do | ||
value { Faker::Number.between(0, 5) } | ||
local { create(:local) } | ||
local { FactoryBot.create :local } | ||
user_identifier { FactoryBot.create :user_identifier } | ||
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