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
{ | |
"id": 1, | |
"email": "pippo@disney.com", | |
"name": "Pippo", | |
"created_at": "2013-11-10T01:38:38.693Z", | |
"updated_at": "2013-11-10T01:38:38.693Z", | |
"waiting_groups": [ | |
{ | |
"id": 1, | |
"name": "rave", |
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
require 'spec_helper' | |
describe UsersUnitMembership do | |
describe "Validations" do | |
it "validates that User is not in waiting list" do | |
users_unit = FactoryGirl.create(:users_unit) | |
user = FactoryGirl.create(:user) | |
users_unit.group.waiters << user |
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
module Api | |
module V1 | |
class WaitingListsController < ApplicationController | |
before_action except: :update do | |
@customer = Customer.find(params[:customer_id]) | |
end | |
def show | |
render json: @customer.waiting_list |
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
def show | |
if params[:customer_id] | |
customer = Customer.find(params[:customer_id]) | |
if customer | |
render json: customer.waiting_list | |
else | |
render status: :bad_request | |
end | |
else | |
render json: WaitingList.find(params[:id]) |
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
Started PUT "/api/v1/customers/2" for 127.0.0.1 at 2013-10-28 01:03:26 +0100 | |
Processing by Api::V1::CustomersController#update as */* | |
Parameters: {"customer"=>{"name"=>"coope", "waiting_list_attributes"=>[{}]}, "id"=>"2"} | |
Customer Load (1.5ms) SELECT "customers".* FROM "customers" WHERE "customers"."id" = ? LIMIT 1 [["id", "2"]] | |
Unpermitted parameters: waiting_list_attributes | |
(0.1ms) begin transaction | |
(0.2ms) commit transaction | |
Completed 200 OK in 74ms (Views: 1.3ms | ActiveRecord: 3.3ms) |
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
class UsersController < ApplicationController | |
def create | |
user = User.new(users_params) | |
if user.save | |
render json: user | |
else | |
render json: user | |
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
Failures: | |
1) Membership Validations | |
Failure/Error: should validate_uniqueness_of(:member_id).scoped_to(:memberable_id, :memberable_type) } | |
NameError: | |
uninitialized constant Customes | |
# ./spec/models/membership_spec.rb:13:in `block (3 levels) in <top (required)>' | |
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
2.0.0p195 :008 > c.users_units | |
UsersUnit Load (0.3ms) SELECT "users_units".* FROM "users_units" WHERE "users_units"."customer_id" = 1 | |
=> [#<UsersUnit id: 2, customer_id: 1, name: "my uf", created_at: "2013-10-26 19:20:14", updated_at: "2013-10-26 19:20:14">] | |
2.0.0p195 :009 > u.customer | |
=> #<Customer id: 1, name: "Coope 1", created_at: "2013-10-26 16:47:09", updated_at: "2013-10-26 16:47:09"> | |
2.0.0p195 :010 > u.customer = Customer.last |
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
# Create a DB dump | |
# | |
# @param [String] dump path | |
# @return [Object] | |
def self.dump_to(dump_path) | |
adapter_config = ActiveRecord::Base.connection.instance_values["config"] | |
case adapter_config[:adapter] | |
when "mysql", "mysql2" | |
stdin, stdout, stderr, wait_thr = Open3.popen3('/usr/bin/env mysqldump -uroot adapter_config') | |
stdin.close |
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
# Create a DB dump | |
# | |
# @param [String] dump path | |
# @return [Object] | |
def self.dump_to(dump_path) | |
adapter_config = ActiveRecord::Base.connection.instance_values["config"] | |
case adapter_config[:adapter] | |
when "mysql", "mysql2" | |
stdin, stdout, stderr, wait_thr = Open3.popen3('/usr/bin/env mysqldump -uroot adapter_config > #{dump_path}') | |
when "sqlite3" |