Skip to content

Instantly share code, notes, and snippets.

@lucascaton
Created January 13, 2016 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucascaton/1b90ddf047a4701c774b to your computer and use it in GitHub Desktop.
Save lucascaton/1b90ddf047a4701c774b to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'sqlite3'
gem 'activerecord', '4.2.4'
gem 'rspec', '3.3.0'
gem 'shoulda-matchers', '3.0.0'
end
require 'active_record'
require 'rspec/autorun'
require 'logger'
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :active_record
with.library :active_model
end
end
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :posts do |t|
t.integer :comment_count
end
end
class Post < ActiveRecord::Base
validates_numericality_of :comment_count, only_integer: true, greater_than_or_equal_to: 0, allow_nil: true
end
RSpec.describe Post, type: :model do
it { should validate_numericality_of(:comment_count).only_integer.is_greater_than_or_equal_to(0).allow_nil }
end
@lucascaton
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment