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
RSpec::Matchers.define :have_same_attributes_as do |expected| | |
ignored_attributes = ['id', 'updated_at', 'created_at'] | |
match do |actual| | |
actual.attributes.except(*ignored_attributes) == expected.attributes.except(*ignored_attributes) | |
end | |
chain :except do |*attributes| | |
ignored_attributes += attributes.map {|a| a.to_s} | |
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
# config/initializers/to_boolean.rb | |
module ToBoolean | |
def to_bool | |
return true if ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(self) | |
return false | |
end | |
end | |
class NilClass; include ToBoolean; 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
RSpec.describe MyController, type: :controller do | |
include ActiveJob::TestHelper | |
describe "..." do | |
it "enqueues the job with the right arguments" do | |
expect { | |
@bookmark = post :create, {:bookmark => valid_attributes} | |
}.to have_enqueued_job(SlackNotifierJob).with { |args| | |
expect(args).to eq(["new_bookmark", @bookmark]) | |
} |
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
context 'when changing the selected materials', :js => true, focus: true do | |
include MoneyRails::ActionViewExtension | |
it 'updates the offers' do | |
# bla bla | |
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
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.clean_with(:truncation) | |
end | |
config.before(:each) do | |
DatabaseCleaner.strategy = :transaction | |
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
/* | |
* author: @jameslafa | |
* More details on http://blog.james-lafa.fr/angularjs-how-to-mock-mixpanel-inside-for-your-tests/ | |
*/ | |
class MixpanelMock | |
debug = false | |
log: (event, data) -> | |
if @debug |
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
# It extends activeadmin to show pretty boolean values | |
# | |
# config/initializers/active_admin.rb | |
module ActiveAdmin | |
module Views | |
class TableFor | |
def bool_column(attribute) | |
column(attribute){ |model| model[attribute] ? '✔'.html_safe : '✗'.html_safe } | |
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
RSpec::Matchers.define :match_exactly do |expected_match_count, selector| | |
match do |context| | |
matching = context.all(selector) | |
@matched = matching.size | |
@matched == expected_match_count | |
end | |
failure_message_for_should do | |
"expected '#{selector}' to match exactly #{expected_match_count} elements, but matched #{@matched}" | |
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
# Rebuild database from schema.rb | |
rake db:reset | |
# But this rebuild database from all migrations | |
rake db:drop db:create db:migrate db:seed |