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 |
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 |
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] |
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 |
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 |
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 |
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 |
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 |
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 |
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