spec/unit/resource_collection_spec.rb in activeadmin-0.6.6 vs spec/unit/resource_collection_spec.rb in activeadmin-1.0.0.pre1
- old
+ new
@@ -1,62 +1,55 @@
-require 'spec_helper'
+require 'rails_helper'
require 'active_admin/resource_collection'
describe ActiveAdmin::ResourceCollection do
let(:application) { ActiveAdmin::Application.new }
let(:namespace) { ActiveAdmin::Namespace.new application, :admin }
let(:collection) { ActiveAdmin::ResourceCollection.new }
+ let(:resource) { double resource_name: "MyResource" }
- it { should respond_to :[] }
- it { should respond_to :add }
- it { should respond_to :each }
- it { should respond_to :has_key? }
- it { should respond_to :keys }
- it { should respond_to :values }
- it { should respond_to :size }
- it { should respond_to :to_a }
+ it { is_expected.to respond_to :[] }
+ it { is_expected.to respond_to :add }
+ it { is_expected.to respond_to :each }
+ it { is_expected.to respond_to :has_key? }
+ it { is_expected.to respond_to :keys }
+ it { is_expected.to respond_to :values }
+ it { is_expected.to respond_to :size }
+ it { is_expected.to respond_to :to_a }
it "should have no resources when new" do
- collection.should be_empty
+ expect(collection).to be_empty
end
it "should be enumerable" do
- resource = mock :resource_name => "MyResource"
collection.add(resource)
- collection.each{ |r| r.should == resource }
+ collection.each{ |r| expect(r).to eq resource }
end
it "should return the available keys" do
- resource = mock :resource_name => "MyResource"
collection.add resource
- collection.keys.should == [resource.resource_name]
+ expect(collection.keys).to eq [resource.resource_name]
end
describe "#add" do
- let(:resource){ mock :resource_name => "MyResource" }
-
it "should return the resource" do
- collection.add(resource).should == resource
+ expect(collection.add(resource)).to eq resource
end
it "should add a new resource" do
collection.add(resource)
- collection.values.should == [resource]
+ expect(collection.values).to eq [resource]
end
it "should be available by name" do
collection.add(resource)
- collection[resource.resource_name].should == resource
+ expect(collection[resource.resource_name]).to eq resource
end
- end
- describe "adding a new resource when the key already exists" do
- let(:resource){ mock :resource_name => "MyResource" }
-
- it "should not add a new resource" do
+ it "shouldn't happen twice" do
collection.add(resource); collection.add(resource)
- collection.values.should == [resource]
+ expect(collection.values).to eq [resource]
end
it "shouldn't allow a resource name mismatch to occur" do
expect {
ActiveAdmin.register Category
@@ -76,17 +69,17 @@
let(:renamed) { ActiveAdmin::Resource.new namespace, Category, as: "Subcategory" }
it "when the renamed version is added first" do
collection.add renamed
collection.add resource
- collection.values.should include(resource, renamed)
+ expect(collection.values).to include(resource, renamed)
end
it "when the renamed version is added last" do
collection.add resource
collection.add renamed
- collection.values.should include(resource, renamed)
+ expect(collection.values).to include(resource, renamed)
end
end
end
describe "#[]" do
@@ -102,41 +95,41 @@
collection.add resource
collection.add inherited_resource
end
it "should find resource by class" do
- collection[resource_class].should == resource
+ expect(collection[resource_class]).to eq resource
end
it "should find resource by class string" do
- collection[resource_class.to_s].should == resource
+ expect(collection[resource_class.to_s]).to eq resource
end
it "should find inherited resource by class" do
- collection[inherited_resource_class].should == inherited_resource
+ expect(collection[inherited_resource_class]).to eq inherited_resource
end
it "should find inherited resource by class string" do
- collection[inherited_resource_class.to_s].should == inherited_resource
+ expect(collection[inherited_resource_class.to_s]).to eq inherited_resource
end
it "should return nil when the resource_class does not respond to base_class and it is not in the collection" do
- collection[mock].should == nil
+ expect(collection[double]).to eq nil
end
it "should return nil when a resource class is NOT in the collection" do
- collection[unregistered_class].should == nil
+ expect(collection[unregistered_class]).to eq nil
end
end
context "without inherited resources" do
before do
collection.add resource
end
it "should find resource by inherited class" do
- collection[inherited_resource_class].should == resource
+ expect(collection[inherited_resource_class]).to eq resource
end
end
context "with a renamed resource" do
let(:renamed_resource) { ActiveAdmin::Resource.new namespace, resource_class, as: name }
@@ -145,21 +138,21 @@
before do
collection.add renamed_resource
end
it "should find resource by class" do
- collection[resource_class].should == renamed_resource
+ expect(collection[resource_class]).to eq renamed_resource
end
it "should find resource by class string" do
- collection[resource_class.to_s].should == renamed_resource
+ expect(collection[resource_class.to_s]).to eq renamed_resource
end
it "should find resource by name" do
- collection[name].should == renamed_resource
+ expect(collection[name]).to eq renamed_resource
end
end
end
- pending "specs for subclasses of Page and Resource"
+ skip "specs for subclasses of Page and Resource"
end