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

Commit

Permalink
Clean up spec styles
Browse files Browse the repository at this point in the history
  • Loading branch information
laserlemon committed Mar 6, 2013
1 parent adddc8f commit 9ce5135
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 106 deletions.
10 changes: 5 additions & 5 deletions spec/periscope/adapters/active_record_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require "spec_helper"

describe 'Periscope::Adapters::ActiveRecord', :adapter => 'active_record' do
let(:model){ User }
describe "Periscope::Adapters::ActiveRecord", adapter: "active_record" do
let(:model) { User }

include_examples 'periscopic'
include_examples 'databasic'
include_examples "periscopic"
include_examples "databasic"
end
10 changes: 5 additions & 5 deletions spec/periscope/adapters/data_mapper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require "spec_helper"

describe 'Periscope::Adapters::DataMapper', :adapter => 'data_mapper' do
let(:model){ User }
describe "Periscope::Adapters::DataMapper", adapter: "data_mapper" do
let(:model) { User }

include_examples 'periscopic'
include_examples 'databasic'
include_examples "periscopic"
include_examples "databasic"
end
10 changes: 5 additions & 5 deletions spec/periscope/adapters/mongo_mapper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require "spec_helper"

describe 'Periscope::Adapters::MongoMapper', :adapter => 'mongo_mapper' do
let(:model){ User }
describe "Periscope::Adapters::MongoMapper", adapter: "mongo_mapper" do
let(:model) { User }

include_examples 'periscopic'
include_examples 'databasic'
include_examples "periscopic"
include_examples "databasic"
end
10 changes: 5 additions & 5 deletions spec/periscope/adapters/mongoid_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require "spec_helper"

describe 'Periscope::Adapters::Mongoid', :adapter => 'mongoid' do
let(:model){ User }
describe "Periscope::Adapters::Mongoid", adapter: "mongoid" do
let(:model) { User }

include_examples 'periscopic'
include_examples 'databasic'
include_examples "periscopic"
include_examples "databasic"
end
6 changes: 3 additions & 3 deletions spec/periscope_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'spec_helper'
require "spec_helper"

describe Periscope, :adapter => nil do
describe Periscope, adapter: nil do
let(:model) do
klass = MockModel.new
klass.extend(Periscope)
klass
end

include_examples 'periscopic'
include_examples "periscopic"
end
32 changes: 16 additions & 16 deletions spec/shared/databasic.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
shared_examples 'databasic' do
context 'with a database' do
shared_examples "databasic" do
context "with a database" do
before do
create(:user, :gender => 'male', :salary => 1_000_000)
create(:user, :gender => 'female', :salary => 2_000_000)
create(:user, :gender => 'female', :salary => 3_000_000)
create(:user, gender: "male", salary: 1_000_000)
create(:user, gender: "female", salary: 2_000_000)
create(:user, gender: "female", salary: 3_000_000)
end

it 'returns all records for no params' do
it "returns all records for no params" do
User.periscope.count.should == 3
end

it 'respects existing scoping' do
it "respects existing scoping" do
User.female.periscope.count.should == 2
end

it 'links to existing scoping' do
it "links to existing scoping" do
User.scope_accessible(:makes)
User.female.periscope(:makes => 3_000_000).count.should == 1
User.female.periscope(makes: 3_000_000).count.should == 1
end

it 'applies named scopes' do
User.scope_accessible(:male, :boolean => true)
User.periscope(:male => true).count.should == 1
it "applies named scopes" do
User.scope_accessible(:male, boolean: true)
User.periscope(male: true).count.should == 1
end

it 'applies class methods' do
it "applies class methods" do
User.scope_accessible(:gender)
User.periscope(:gender => 'male').count.should == 1
User.periscope(gender: "male").count.should == 1
end

it 'chains scopes' do
it "chains scopes" do
User.scope_accessible(:gender, :makes)
User.periscope(:gender => 'female', :makes => 3_000_000).count.should == 1
User.periscope(gender: "female", makes: 3_000_000).count.should == 1
end
end
end
134 changes: 67 additions & 67 deletions spec/shared/periscopic.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
shared_examples 'periscopic' do
context 'without a database' do
shared_examples "periscopic" do
context "without a database" do
before do
model.stub(:periscope_default_scope => model)
model.stub(periscope_default_scope: model)
end

def expect_scopes(calls)
Expand All @@ -10,123 +10,123 @@ def expect_scopes(calls)
end
end

it 'uses the default scope for no params' do
it "uses the default scope for no params" do
scoped = mock.as_null_object
model.should_receive(:periscope_default_scope).once.and_return(scoped)
model.periscope.should == scoped
end

it 'uses the default scope for empty params' do
it "uses the default scope for empty params" do
scoped = mock.as_null_object
model.should_receive(:periscope_default_scope).once.and_return(scoped)
model.periscope({}).should == scoped
end

it 'ignores protected scopes' do
it "ignores protected scopes" do
model.should_not_receive(:foo)
model.periscope(:foo => 'bar')
model.periscope(foo: "bar")
end

it 'calls accessible scopes with values' do
expect_scopes(:foo => ['bar'])
it "calls accessible scopes with values" do
expect_scopes(foo: ["bar"])
model.scope_accessible(:foo)
model.periscope(:foo => 'bar')
model.periscope(foo: "bar")
end

it 'recognizes accessible scopes, whether string or symbol' do
expect_scopes(:foo => ['baz'], :bar => ['mitzvah'])
model.scope_accessible(:foo, 'bar')
model.periscope('foo' => 'baz', :bar => 'mitzvah')
it "recognizes accessible scopes, whether string or symbol" do
expect_scopes(foo: ["baz"], bar: ["mitzvah"])
model.scope_accessible(:foo, "bar")
model.periscope("foo" => "baz", bar: "mitzvah")
end

it 'ignores protected scopes when mixed with accessible scopes' do
expect_scopes(:foo => ['baz'])
it "ignores protected scopes when mixed with accessible scopes" do
expect_scopes(foo: ["baz"])
model.should_not_receive(:bar)
model.scope_accessible(:foo)
model.periscope(:foo => 'baz', :bar => 'mitzvah')
model.periscope(foo: "baz", bar: "mitzvah")
end

it 'assigns method names in order to avoid collisions' do
expect_scopes(:begins_after => ['1983-05-28'], :ends_before => ['2083-05-28'])
model.scope_accessible(:begin, :method => :begins_after)
model.scope_accessible(:end, :method => :ends_before)
model.periscope(:begin => '1983-05-28', :end => '2083-05-28')
it "assigns method names in order to avoid collisions" do
expect_scopes(begins_after: ["1983-05-28"], ends_before: ["2083-05-28"])
model.scope_accessible(:begin, method: :begins_after)
model.scope_accessible(:end, method: :ends_before)
model.periscope(begin: "1983-05-28", end: "2083-05-28")
end

it 'prefixes method names in order to avoid collisions' do
expect_scopes(:scope_for_begin => ['1983-05-28'], :scope_for_end => ['2083-05-28'])
model.scope_accessible(:begin, :end, :prefix => 'scope_for_')
model.periscope(:begin => '1983-05-28', :end => '2083-05-28')
it "prefixes method names in order to avoid collisions" do
expect_scopes(scope_for_begin: ["1983-05-28"], scope_for_end: ["2083-05-28"])
model.scope_accessible(:begin, :end, prefix: "scope_for_")
model.periscope(begin: "1983-05-28", end: "2083-05-28")
end

it 'suffixes method names in order to avoid collisions' do
expect_scopes(:begin_scope => ['1983-05-28'], :end_scope => ['2083-05-28'])
model.scope_accessible(:begin, :end, :suffix => '_scope')
model.periscope(:begin => '1983-05-28', :end => '2083-05-28')
it "suffixes method names in order to avoid collisions" do
expect_scopes(begin_scope: ["1983-05-28"], end_scope: ["2083-05-28"])
model.scope_accessible(:begin, :end, suffix: "_scope")
model.periscope(begin: "1983-05-28", end: "2083-05-28")
end

it 'prefixes and suffixes method names' do
expect_scopes(:foo_begin_bar => ['1983-05-28'], :foo_end_bar => ['2083-05-28'])
model.scope_accessible(:begin, :end, :prefix => 'foo_', :suffix => '_bar')
model.periscope(:begin => '1983-05-28', :end => '2083-05-28')
it "prefixes and suffixes method names" do
expect_scopes(foo_begin_bar: ["1983-05-28"], foo_end_bar: ["2083-05-28"])
model.scope_accessible(:begin, :end, prefix: "foo_", suffix: "_bar")
model.periscope(begin: "1983-05-28", end: "2083-05-28")
end

it 'allows multiple scope_accessible calls' do
expect_scopes(:foo => ['baz'], :bar => ['mitzvah'])
it "allows multiple scope_accessible calls" do
expect_scopes(foo: ["baz"], bar: ["mitzvah"])
model.scope_accessible(:foo)
model.scope_accessible(:bar)
model.periscope(:foo => 'baz', :bar => 'mitzvah')
model.periscope(foo: "baz", bar: "mitzvah")
end

it 'overrides scope_accessible options per call' do
expect_scopes(:start => ['1983-05-28'], :end_scope => ['2083-05-28'])
model.scope_accessible(:start, :end, :suffix => '_scope')
it "overrides scope_accessible options per call" do
expect_scopes(start: ["1983-05-28"], end_scope: ["2083-05-28"])
model.scope_accessible(:start, :end, suffix: "_scope")
model.scope_accessible(:start)
model.periscope(:start => '1983-05-28', :end => '2083-05-28')
model.periscope(start: "1983-05-28", end: "2083-05-28")
end

it 'allows custom parameter parsing via proc' do
expect_scopes(:foo => ['BAR'])
model.scope_accessible(:foo, :parser => proc{|p| [p.upcase] })
model.periscope(:foo => 'bar')
it "allows custom parameter parsing via proc" do
expect_scopes(foo: ["BAR"])
model.scope_accessible(:foo, parser: proc { |p| [p.upcase] })
model.periscope(foo: "bar")
end

it 'allows custom parameter parsing via custom parser' do
expect_scopes(:foo => ['BAR'])
it "allows custom parameter parsing via custom parser" do
expect_scopes(foo: ["BAR"])
parser = mock.as_null_object
parser.should_receive(:call).once.with('bar').and_return(['BAR'])
model.scope_accessible(:foo, :parser => parser)
model.periscope(:foo => 'bar')
parser.should_receive(:call).once.with("bar").and_return(["BAR"])
model.scope_accessible(:foo, parser: parser)
model.periscope(foo: "bar")
end

it 'allows parameter exclusion for argument-less scopes' do
expect_scopes(:foo => [])
model.scope_accessible(:foo, :boolean => true)
model.periscope(:foo => 'bar')
it "allows parameter exclusion for argument-less scopes" do
expect_scopes(foo: [])
model.scope_accessible(:foo, boolean: true)
model.periscope(foo: "bar")
end

it 'allows accessible scope exclusion given a falsey param' do
it "allows accessible scope exclusion given a falsey param" do
model.should_not_receive(:foo)
model.scope_accessible(:foo, :boolean => true)
model.periscope(:foo => nil)
model.scope_accessible(:foo, boolean: true)
model.periscope(foo: nil)
end

it 'allows accessible scope exclusion given a falsey parsed value' do
it "allows accessible scope exclusion given a falsey parsed value" do
model.should_not_receive(:foo)
model.scope_accessible(:foo, :boolean => true, :parser => proc{ [nil] })
model.periscope(:foo => 'bar')
model.scope_accessible(:foo, boolean: true, parser: proc { [nil] })
model.periscope(foo: "bar")
end

it 'passes along a nil param' do
expect_scopes(:foo => [nil])
it "passes along a nil param" do
expect_scopes(foo: [nil])
model.scope_accessible(:foo)
model.periscope(:foo => nil)
model.periscope(foo: nil)
end

it 'passes along a nil parsed value' do
expect_scopes(:foo => [nil])
model.scope_accessible(:foo, :parser => proc{ [nil] })
model.periscope(:foo => 'bar')
it "passes along a nil parsed value" do
expect_scopes(foo: [nil])
model.scope_accessible(:foo, parser: proc { [nil] })
model.periscope(foo: "bar")
end
end
end

0 comments on commit 9ce5135

Please sign in to comment.