View gist:340055
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
select | |
question_id, cnt, total_cnt, 1.0 * cnt / total_cnt as ratio | |
from ( | |
select question_id, sum(case when correct='f' then 1 else 0 end) as cnt,count(question_id) as total_cnt from quiz_questions group by question_id | |
) | |
order by ratio desc |
View contain_within_matcher.rb
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
# Must have Nokogiri gem installed and save this file in your spec/support dir | |
# Allows you to write cleaner/faster specs in your views (50% faster than css_select) | |
# Increased readability in your spec doc | |
# ex. | |
# rendered.should contain('my heading').within('h1') # searches all H1 tags for 'my heading' | |
# or | |
# rendered.should contain('my string') # searches entire rendered string for 'my string' | |
class Within | |
def initialize(expected, css_selector) | |
@expected = expected |
View gist:1137015
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
# factorial | |
(1..5).inject(&:*) # => 120 | |
# reverse | |
(1..5).inject([]) { |val, v| [v] + val } # => [5, 4, 3, 2, 1] | |
# fibonacci numbers | |
(1...5 - 1).inject([0, 1]) { |val, v| val << val[-2] + val[-1] } # => [0, 1, 1, 2, 3] |
View post_test.rb
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
gem "minitest" | |
require "minitest/spec" | |
require "minitest/autorun" | |
require "active_model" | |
require "test/unit" | |
require "valid_attribute" | |
require "turn" | |
class MiniTest::Unit::TestCase | |
extend ValidAttribute::Method |
View post_test.rb
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
gem "minitest" | |
require "minitest/spec" | |
require "minitest/autorun" | |
require "active_model" | |
require "turn" | |
require "shoulda-matchers" | |
class MiniTest::Unit::TestCase | |
include Shoulda::Matchers::ActiveModel | |
extend Shoulda::Matchers::ActiveModel |
View post_spec.rb
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
# you have to use https://github.com/wojtekmach/valid_attribute/tree/minitest | |
require "minitest/autorun" | |
require "minitest/matchers" | |
require "active_model" | |
require "valid_attribute" | |
class Post | |
include ActiveModel::Validations | |
attr_accessor :title |
View test.rb
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
gem "minitest" | |
require "minitest/spec" | |
require "minitest/autorun" | |
class ControllerSpec < MiniTest::Spec | |
def self.inherited klass | |
p "id: #{klass.object_id}" | |
p "name: #{klass.name}" | |
super | |
end |
View application.css.sass
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
.clearfix | |
label | |
margin-right: 20px | |
&.boolean, &.check_boxes span, &.radio span | |
padding-left: 150px | |
height: 27px | |
label | |
float: left | |
width: auto |
View gist:1336382
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 Capybara::PolymorphicVisit | |
def visit(*args) | |
if args.first.is_a? String | |
super *args | |
else | |
super polymorphic_url(*args) | |
end | |
end | |
end |
View slim.rb
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 Tilt | |
class HandlebarsSlimTemplate < ::Slim::Template; end | |
register HandlebarsSlimTemplate, :handlebars_slim | |
end | |
class Slim::EmbeddedEngine | |
register :handlebars, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" } | |
register :handlebars_slim, TagEngine, tag: :script, attributes: { type: "text/x-handlebars" }, engine: StaticTiltEngine | |
end |
OlderNewer