Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

52 lines (39 sloc) 1.332 kb
require 'test_helper'
require 'groupy'
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => (RUBY_PLATFORM=="java" ? "jdbcsqlite3" : "sqlite3"),
:database => ":memory:"
)
ActiveRecord::Schema.define(:version => 0) do
create_table :somethings, :force => true do |t|
t.string :size
end
end
class Something < ActiveRecord::Base
include Groupy
groupy :size, :suffix => true do
value :small
value :medium
value :large
end
end
class WithDatabaseTest < ActiveSupport::TestCase
test "scopes" do
assert_equal [], Something.small_sizes.all
assert_equal 0, Something.small_sizes.count
assert_equal [], Something.medium_sizes.all
assert_equal 0, Something.medium_sizes.count
small1 = Something.create!(:size => "small")
medium = Something.create!(:size => "medium")
small2 = Something.create!(:size => "small")
assert_equal [small1, small2], Something.small_sizes.all
assert_equal 2, Something.small_sizes.count
assert_equal [medium], Something.medium_sizes.all
assert_equal 1, Something.medium_sizes.count
end
test "subgroup shortcut" do
assert_equal ["small", "medium", "large"], Something.sizes(:all)
assert_equal ["small"], Something.sizes(:small)
end
end
Jump to Line
Something went wrong with that request. Please try again.