forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscope_spec.rb
More file actions
55 lines (44 loc) · 1.77 KB
/
scope_spec.rb
File metadata and controls
55 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'spec_helper'
describe ActiveAdmin::Scope do
describe "creating a scope" do
subject{ scope }
context "when just a scope method" do
let(:scope) { ActiveAdmin::Scope.new :published }
its(:name) { should == "Published"}
its(:id) { should == "published"}
its(:scope_method) { should == :published }
end
context "when scope method is :all" do
let(:scope) { ActiveAdmin::Scope.new :all }
its(:name) { should == "All"}
its(:id) { should == "all"}
# :all does not return a chain but an array of active record
# instances. We set the scope_method to nil then.
its(:scope_method) { should == nil }
its(:scope_block) { should == nil }
end
context "when a name and scope method" do
let(:scope) { ActiveAdmin::Scope.new "With API Access", :with_api_access }
its(:name) { should == "With API Access"}
its(:id) { should == "with_api_access"}
its(:scope_method) { should == :with_api_access }
end
context "when a name and scope block" do
let(:scope) { ActiveAdmin::Scope.new("My Scope"){|s| s } }
its(:name) { should == "My Scope"}
its(:id) { should == "my_scope"}
its(:scope_method) { should == nil }
its(:scope_block) { should be_a(Proc)}
end
end # describe "creating a scope"
describe "#display_if_block" do
it "should return true by default" do
scope = ActiveAdmin::Scope.new(:default)
scope.display_if_block.call.should == true
end
it "should return the :if block if set" do
scope = ActiveAdmin::Scope.new(:with_block, nil, :if => proc{ false })
scope.display_if_block.call.should == false
end
end
end