spec/unit/helpers/collection_spec.rb in activeadmin-1.0.0.pre4 vs spec/unit/helpers/collection_spec.rb in activeadmin-1.0.0.pre5
- old
+ new
@@ -1,22 +1,17 @@
require 'rails_helper'
-describe ActiveAdmin::Helpers::Collection do
+RSpec.describe ActiveAdmin::Helpers::Collection do
include ActiveAdmin::Helpers::Collection
- before(:all) do
- Post.delete_all
+ before do
Post.create!(title: "A post")
Post.create!(title: "A post")
Post.create!(title: "An other post")
end
- after(:all) do
- Post.delete_all
- end
-
describe "#collection_size" do
it "should return the collection size for an ActiveRecord class" do
expect(collection_size(Post.where(nil))).to eq 3
end
@@ -30,17 +25,25 @@
it "should return the collection size for a collection with group by, select and custom order" do
expect(collection_size(Post.select("title, count(*) as nb_posts").group(:title).order("nb_posts"))).to eq 2
end
+ it "should return the collection size for an Array" do
+ expect(collection_size(Post.where(title: "A post").to_a)).to eq 2
+ end
+
it "should take the defined collection by default" do
def collection; Post.where(nil); end
expect(collection_size).to eq 3
def collection; Post.where(title: "An other post"); end
expect(collection_size).to eq 1
+
+ def collection; Post.where(title: "A post").to_a end
+
+ expect(collection_size).to eq 2
end
end
describe "#collection_is_empty?" do
it "should return true when the collection is empty" do