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 CaseTest | |
def initialize(number) | |
@number = number | |
end | |
def test | |
case @number | |
when it_is_eight? | |
'eight' | |
when it_is_five? |
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 fizzbuzz(number) | |
case [number % 3, number % 5] | |
in [0, 0] then 'FizzBuzz' | |
in [0, _] then 'Fizz' | |
in [_, 0] then 'Buzz' | |
end | |
end | |
puts fizzbuzz(15) # => 'FizzBuzz' | |
puts fizzbuzz(3) # => 'Fizz' |
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
;; To run this one you need to have Leiningen installed. | |
;; cat reviewers.clj | lein repl | |
(def team | |
["Andrzej" "Artur" "Jarek" "Junior" "Oskar" "Piotr" "Paweł" "Sebastian"]) | |
(def me "Sebastian") | |
(->> team | |
(remove #(= %1 me)) | |
(shuffle) |
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 'benchmark' | |
def test_exception | |
raise "test exception" unless true | |
2 + 2 | |
rescue | |
4 | |
end | |
def test_unless |
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 TravelDocumentPolicy | |
def create? | |
user.agent? || user.superagent? | |
end | |
def update? | |
create? | |
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 Profile < ActiveRecord::Base | |
validates :facebook_profile, url: { allow_blank: true } | |
end | |
# failing spec | |
specify "www.facebook.com/username should be valid facebook profile url" do | |
profile.facebook_profile = "www.facebook.com/username" |
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
# controller code | |
current_merchant.payments.find(params[:id]) | |
# test code | |
stub(Merchant).find(@merchant_id) { @merchant } | |
stub(@merchant).payments.stub!.find(@payment.id.to_s) { @payment } | |
login_merchant(@merchant) |
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 "rubygems" | |
require "minitest/autorun" | |
describe "#let" do | |
describe "problematic names" do | |
let(:message) { "It is my message" } | |
it "is not accessible" do | |
message.must_equal "It is my message" | |
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 validates if passed record's attribute value has proper Liquid template syntax. | |
class LiquidSyntaxValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, template) | |
Liquid::Template.parse(template) | |
rescue Liquid::SyntaxError | |
record.errors.add(attribute, :liquid_syntax_error) | |
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
Offer | |
.with_nokaut_category_id(10745) | |
.and({ | |
"$or" => [ | |
{ "is_trash"=>false }, { "is_trash" => { "$exists" => false } } | |
] | |
}, | |
{ | |
"$or" => [ | |
{ "xml_category" => /ultrad.wi.kowe/ }, |
NewerOlder