Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
add basic spec and ci stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
markets committed Mar 30, 2014
1 parent ea2f2a1 commit 12d89b0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
@@ -0,0 +1,4 @@
language: ruby
rvm:
- 2.0.0
- 1.9.3
9 changes: 7 additions & 2 deletions Gemfile
@@ -1,3 +1,8 @@
source "https://rubygems.org"
source 'https://rubygems.org'

gemspec
gemspec

group :development, :test do
gem 'rspec'
gem 'sqlite3'
end
8 changes: 7 additions & 1 deletion Rakefile
@@ -1 +1,7 @@
require "bundler/gem_tasks"
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new

task :default => :spec
task :test => :spec
47 changes: 47 additions & 0 deletions spec/spec_helper.rb
@@ -0,0 +1,47 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

require 'active_record'
require 'unscoped_associations'

ActiveRecord::Base.logger = Logger.new(STDOUT)

ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)

ActiveRecord::Schema.define do
self.verbose = false

create_table :users, :force => true do |t|
t.boolean :active
end

create_table :comments, :force => true do |t|
t.integer :user_id
t.boolean :public
end
end

class User < ActiveRecord::Base
has_many :comments
has_many :all_comments, class_name: 'Comment', unscoped: true
has_one :last_comment, class_name: 'Comment', order: 'id DESC', unscoped: true

default_scope where( active: true )
end

class Comment < ActiveRecord::Base
belongs_to :user, unscoped: true

default_scope where( public: true )
end

RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
config.mock_with :rspec
config.order = 'random'
end
10 changes: 10 additions & 0 deletions spec/unscoped_associations_spec.rb
@@ -0,0 +1,10 @@
require 'spec_helper'

describe UnscopedAssociations do
it 'belongs_to with unscoped option should skip default_scope' do
user = User.create(:active => false)
comment = Comment.create(:user_id => user.id)

expect(comment.user).to eq(user)
end
end
2 changes: 2 additions & 0 deletions unscoped_associations.gemspec
Expand Up @@ -19,5 +19,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "activerecord", ">= 0"

spec.add_development_dependency "debugger"
spec.add_development_dependency "rspec"
spec.add_development_dependency "sqlite3"
end

0 comments on commit 12d89b0

Please sign in to comment.