Find out branches containing a commit
If you have a commit and you want to see in what branches is is included, you have to write this:
git branch -r --contains [COMMIT-SHA]
-r is for remote
Related cards:
Rebase your feature branches
Regularly, but at least before merging your feature branches, rebase them to get rid of "fix typo" and "wip" commits.
Getting rid of unnecessary commits
Let's say you do a git rebase -i HEAD~~~~
and have this...
Database: Scopes, migrations, and indices
Wether you modify an existing named scope or add a new one, or when you write a new query, make sure you have the proper indices.
This particularly applies if you're going to run non-trivial queries of course (admin backends, analytics, etc).
##...
ActiveRecord::NamedScopes (2.3.x) obtaining the SQL conditions
It's a good pratice to chain several named scopes like:
Property.listable.for_2_or_more_guests.best_10_properties
Now, to make the lesson more valuable let's assume the following code:
Property.scoped(:conditions => "foo = 2").scoped(...
When you set date attributes, you should not pass times
As you know, time zones make stuff a bit more difficult but are necessary.
A time-zoned record is converted to UTC using to_s(:db)
to be st...
Method return value should always be of same type
One of the main source of bugs and complexity in the code is when a functional method (that we expect to return a value) return different values under different circumstances.
For example, we ruby programmers have a bad habit of returning nil fro...
Git Branch naming
This is how we name branches :
-
<team>/<story>-<id>
(features) -
fix/<team>/<story>-<id>
(bugs)
story
is an dash-delimited version of the story name, and id
the Pivotal story number.
Examples :
-
supply/belvilla-naming-1234567
-...
Killing wkhtmltopdf during cucumber
wkhtmltopdf
hangs on mac during cucumber unless we click on it. The main reason is with the version we use which is 0.11.0_rc1 and in out app/bin we have another version and it is a known issue with these versions. The fix is to go to 0.9.9, to ...
Add indexes on foreign keys when you create a migration (with foreign key)
Whenever you make a migration to add a foreign key, you should also add an index for it
def self.up
add_column :comments, :user_id, :integer
add_index :comments, :user_id
end
Creating a gem in lib folder
Go to lib folder and use bundler to generate main files for a gem:
$ bundle gem test_gem
create test_gem/Gemfile
create test_gem/Rakefile
create test_gem/LICENSE
create test_gem/README.md
...
DateTimes are Dates, beware
Given:
datetime = DateTime.now
date = datetime.to_date #or Date.today
will assert:
datetime.is_a? Date == true
datetime.is_a? DateTime == true
datetime.instance_of? Date == false
datetime.instance_of? DateTime == true
In case y...