Sha256: b4cbe1a763fe8b92a907c4331cd8ee4cf8abdeccec604c11ba9b56d8e964a1e8

Contents?: true

Size: 1.79 KB

Versions: 62

Compression:

Stored size: 1.79 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
      collection_size(Post).should == 3
    end

    it "should return the collection size for an ActiveRecord::Relation" do
      collection_size(Post.where(:title => "A post")).should == 2
    end

    it "should return the collection size for a collection with group by" do
      collection_size(Post.group(:title)).should == 2
    end

    it "should return the collection size for a collection with group by, select and custom order" do
      collection_size(Post.select("title, count(*) as nb_posts").group(:title).order("nb_posts")).should == 2
    end

    it "should take the defined collection by default" do
      def collection; Post; end

      collection_size.should == 3

      def collection; Post.where(:title => "An other post"); end

      collection_size.should == 1
    end
  end

  describe "#collection_is_empty?" do
    it "should return true when the collection is empty" do
      collection_is_empty?(Post.where(:title => "Non existing post")).should be_true
    end

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

    it "should take the defined collection by default" do
      def collection; Post; end

      collection_is_empty?.should be_false

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

      collection_is_empty?.should be_true
    end
  end
end

Version data entries

62 entries across 62 versions & 4 rubygems

Version Path
lalala-4.0.0.dev.74 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.73 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.72 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.71 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.66 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.65 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
activeadmin-0.6.0 spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.64 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.63 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.62 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.61 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.60 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.59 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.58 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.57 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.56 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.50 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.46 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
activeadmin-0.5.1 spec/unit/helpers/collection_spec.rb
activeadmin-0.5.0 spec/unit/helpers/collection_spec.rb