Sha256: 502e2590e8dbd5d426fb64deb61b5ef3dc24d011a2fbccac13e63c80a7b8c41a
Contents?: true
Size: 1.83 KB
Versions: 5
Compression:
Stored size: 1.83 KB
Contents
require 'spec_helper' describe ActiveAdmin::Helpers::Collection do include ActiveAdmin::Helpers::Collection before(:all) do Post.delete_all 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.scoped)).to eq 3 end it "should return the collection size for an ActiveRecord::Relation" do expect(collection_size(Post.where(title: "A post"))).to eq 2 end it "should return the collection size for a collection with group by" do expect(collection_size(Post.group(:title))).to eq 2 end 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 take the defined collection by default" do def collection; Post.scoped; end expect(collection_size).to eq 3 def collection; Post.where(title: "An other post"); end expect(collection_size).to eq 1 end end describe "#collection_is_empty?" do it "should return true when the collection is empty" do expect(collection_is_empty?(Post.where(title: "Non existing post"))).to be_true end it "should return false when the collection is not empty" do expect(collection_is_empty?(Post.where(title: "A post"))).to be_false end it "should take the defined collection by default" do def collection; Post.scoped; end expect(collection_is_empty?).to be_false def collection; Post.where(title: "Non existing post"); end expect(collection_is_empty?).to be_true end end end
Version data entries
5 entries across 5 versions & 2 rubygems