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 ApplicationHelper | |
def readable_bool val | |
val ? "Yes" : "No" | |
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
object @user | |
attributes *(@user.class.column_names - %w{id user_type parent_id stamp_id created_at updated_at password_digest access_token}) | |
child :stamp => :contact do |stamp| | |
glue(stamp.contact) { attributes :first_name, :last_name, :email, :contact1, :contact2 } | |
end | |
node(:status) {|user| user.stamp.status } |
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
raw_data = JSON.parse(response.body) | |
@data = Hash.new{|h,k| h[k]=Hash.new(&h.default_proc) } | |
raw_data.each do |u| | |
# u["id"] actually prints u itself?? | |
id = u["id"], name = u["first_name"], l = u["locality"], c = u["city"] | |
@data[id]["first_name"] = name | |
@data[id]["locality"] = l | |
@data[id]["city"] = c | |
@data[id][u["status"]] = u["count"] | |
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
users = Arel::Table.new(:users) | |
stamps = Arel::Table.new(:stamps) | |
contacts = Arel::Table.new(:contacts) | |
children = users.alias | |
query = users.where(users[:user_type].eq('franchisee')) | |
query = query.join(stamps).on(users[:id].eq(stamps[:stampable_id])) | |
query = query.join(contacts).on(contacts[:id].eq(stamps[:contact_id])) | |
query = query.join(children).on(users[:id].eq(children[:parent_id])) | |
query = query.join(stamps).on(children[:id].eq(stamps[:stampable_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
User.includes(stamp: [:contact]).where(:user_type => 'franchisee').joins(:stamp).joins(:children).group("users.id, stamps.status").count("stamps.status") |
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 UsersController do | |
render_views | |
describe 'franchisee actions on users' do | |
before :each do | |
fr = FactoryGirl.build(:user, user_type: 'franchisee') | |
fr.set_stamp(FactoryGirl.build(:stamp), FactoryGirl.build(:contact, email: '[email protected]')) | |
fr.save |
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' | |
require 'faker' | |
describe Stampable do | |
it "throws error if stamp and contact is unset" do | |
expect { FactoryGirl.create(:user) }.to raise_error | |
end | |
it "can be saved if contact and stamp were set" do | |
user = FactoryGirl.build(: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 Contactable | |
def self.set_contact(contact) | |
@contact = Contact.find_by_email(contact[:email]) | |
@contact = Contact.create!(contact) unless @contact.exists? | |
end | |
def self.get_contact | |
@contact | |
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
class CreateInquiries < ActiveRecord::Migration | |
def change | |
create_table :inquiries, id: false do |t| | |
t.primary_key :id, :uuid, :default => 'uuid_generate_v1()' | |
t.belongs_to :contact | |
t.string :inquiry_type | |
t.hstore :metadata | |
t.string :locality | |
t.string :city | |
t.uuid :added_by |
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
{ | |
"user" : { | |
"first_name": "John", | |
"last_name": "Doe", | |
"email": "[email protected]", | |
"mobile": "9876545678", | |
"locality": "Goregaon", | |
"city": "Mumbai", | |
"user_type": "advisor", | |
} |
NewerOlder