This file contains hidden or 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
| # First check is always #respond_to? , if it returns false, then #respond_to_missing? will be called, otherwise #respond_to_missing? | |
| # will never be called. For all regular methods( which has been created by def, define_method, in C-implementation etc), thus we get | |
| # false, while we pass the method name to the #respond_to_missing?. Because, first check has been done inside #respond_to?, and it | |
| # returns true. That's why second output is [true, false]. Because, #foo is a regular method. | |
| # Now why the second output is [true, true] ? The reason, I already explained, again #baz is not a regular method, so first check in | |
| # #respond_to? return false, thus check goes to #respond_to_missing?. As I implemented it, so as per the implementations it is giving | |
| # true, which in turn caused #respond_to? method to returns to true. | |
This file contains hidden or 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.1.2 :008 > Employee.pluck(:age) | |
| (0.4ms) SELECT "employees"."age" FROM "employees" | |
| => [19, 29, 20, 17, 25, 19, 27, nil] | |
| 2.1.2 :009 > Employee.pluck('age) | |
| 2.1.2 :010'> ^C | |
| 2.1.2 :010 > Employee.pluck(:age) | |
| (0.4ms) SELECT "employees"."age" FROM "employees" | |
| => [19, 29, 20, 17, 25, 19, 27, nil] | |
| 2.1.2 :011 > Employee.pluck('age') | |
| (0.7ms) SELECT "employees"."age" FROM "employees" |
This file contains hidden or 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 gist is the correct one taken from Book Beginning Rails 4. The gist they mentioned in the book accidentally contains wrong | |
| # code. Thus I created this gist, so that you can copy the code directly and move on. | |
| class UsersController < ApplicationController | |
| before_action :set_user, only: [:show, :edit, :update, :destroy] | |
| def new | |
| @user = User.new | |
| end |
This file contains hidden or 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
| #------model definition----- | |
| class Book < ActiveRecord::Base | |
| end | |
| class Page < ActiveRecord::Base | |
| belongs_to :book | |
| end | |
| #------migration---------- | |
| class CreateBooks < ActiveRecord::Migration | |
| def change |
This file contains hidden or 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
| Arup-iMac:yelloday shreyas$ git add -p | |
| diff --git a/app/interactors/reporting_groups/list_colleagues.rb b/app/interactors/reporting_groups/list_colleagues.rb | |
| index adc28af..f46f5e3 100644 | |
| --- a/app/interactors/reporting_groups/list_colleagues.rb | |
| +++ b/app/interactors/reporting_groups/list_colleagues.rb | |
| @@ -14,7 +14,4 @@ module ReportingGroups | |
| reporting_group.employees_from_team_sub_reporting_groups | |
| else | |
| reporting_group.users | |
| - end |
This file contains hidden or 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
| describe "#users" do | |
| let(:sub_reporting_group) { FactoryGirl.create(:reporting_group) } | |
| let(:reporting_group) { FactoryGirl.create(:reporting_group, reporting_group_ids: [sub_reporting_group.id]) } | |
| let(:user) { FactoryGirl.create(:user) } | |
| let(:team) { FactoryGirl.create(:team) } | |
| let(:workplace) { FactoryGirl.create(:workplace) } | |
| context "when user belongs to either team_id or workplace_id of a parent reporting group" do | |
| it "shouldn't include user when workplace_id not present" do | |
| user.update(team_id: team.id) |
This file contains hidden or 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
| describe "#dream" do | |
| let(:user1) { User.create } | |
| let(:user2) { User.create } | |
| before do | |
| # below update is on the hand of God | |
| user1.update(:luck => true) | |
| user2.update(:luck => false) | |
| end |
NewerOlder