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
| foo.inject({}) do |hash, bar| | |
| hash.store(a, b) | |
| hash | |
| 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
| def self.stuff | |
| scope = scoped | |
| scope = scope.order("foo") if stuff | |
| scope = scope.joins(:user) if user | |
| scope = scope.where(:foo => "bar") | |
| scope | |
| 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
| def quoted_date(value) #:nodoc: | |
| result = super | |
| if value.acts_like?(:time) && value.respond_to?(:usec) | |
| result = "#{result}.#{sprintf("%06d", value.usec)}" | |
| end | |
| if value.year < 0 | |
| result = result.sub(/^-/, "") + " BC" | |
| end | |
| result |
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
| class MyModel < ActiveRecord::Base | |
| attr_accessible :my_attribute | |
| def my_attribute=(value) | |
| # do something else here... | |
| write_attribute(:my_attribute, value) | |
| end | |
| 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
| package ee.suurhans.algorithms; | |
| import com.sun.org.apache.xpath.internal.functions.FuncFalse; | |
| import java.util.*; | |
| /** | |
| * User: Tanel Suurhans | |
| * Date: 17.02.13 | |
| */ |
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 "database" do | |
| it "should have an unique index on confirmation_token" do | |
| must have_db_index(:confirmation_token).unique(true) | |
| end | |
| it "should have an unique index on email" do | |
| must have_db_index(:email).unique(true) | |
| 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
| User::mass assigment | |
| PASS (0:00:01.141) 0007 anonymous | |
| PASS (0:00:01.158) 0011 anonymous | |
| PASS (0:00:01.175) 0015 anonymous | |
| PASS (0:00:01.193) 0003 anonymous | |
| PASS (0:00:01.211) 0013 anonymous | |
| PASS (0:00:01.230) 0005 anonymous | |
| PASS (0:00:01.248) 0017 anonymous | |
| PASS (0:00:01.265) 0002 anonymous |
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 "validations" do | |
| it { must validate_presence_of(:email) } | |
| it { must ensure_length_of(:email).is_at_most(255) } | |
| end | |
| it "validate email" do | |
| subject.must validate_presence_of(:email) | |
| subject.must ensure_length_of(:email).is_at_most(255) |
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
| SELECT id, | |
| sum(hours) AS totalhours | |
| FROM mytable | |
| GROUP BY id | |
| HAVING sum(hours) > 50; | |
| If you really can't be bothered to write sum() twice, you could consider | |
| a two-level SELECT: | |
| SELECT * FROM |
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
| Bundler could not find compatible versions for gem "devise": | |
| In Gemfile: | |
| locomotive_cms (= 2.0.0.rc12) ruby depends on | |
| devise (~> 2.1.2) ruby | |
| locomotive_cms (= 2.0.0.rc12) ruby depends on | |
| devise (2.2.3) |