Sha256: b8b80f664a59b88a184bcd0e89f22d48b9d7c2f2d8c3af6c22c04f0ebd7c860b

Contents?: true

Size: 1.84 KB

Versions: 20

Compression:

Stored size: 1.84 KB

Contents

require 'rails_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.where(nil))).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.where(nil); 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_truthy
    end

    it "should return false when the collection is not empty" do
      expect(collection_is_empty?(Post.where(title: "A post"))).to be_falsey
    end

    it "should take the defined collection by default" do
      def collection; Post.where(nil); end

      expect(collection_is_empty?).to be_falsey

      def collection; Post.where(title: "Non existing post"); end

      expect(collection_is_empty?).to be_truthy
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/helpers/collection_spec.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.17.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.16.pre spec/unit/helpers/collection_spec.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/helpers/collection_spec.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/helpers/collection_spec.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.15.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.14.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.13.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.12.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.11.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.10.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.9.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.8.pre spec/unit/helpers/collection_spec.rb
activeadmin-1.0.0.pre2 spec/unit/helpers/collection_spec.rb
activeadmin-1.0.0.pre1 spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.7.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.6.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.5.pre spec/unit/helpers/collection_spec.rb