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
activeadmin-0.6.6 spec/unit/helpers/collection_spec.rb
activeadmin-0.6.5 spec/unit/helpers/collection_spec.rb
activeadmin-0.6.4 spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.4.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.3.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.2.pre spec/unit/helpers/collection_spec.rb
activeadmin-0.6.3 spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.1.pre spec/unit/helpers/collection_spec.rb
yousty-activeadmin-1.0.0.pre spec/unit/helpers/collection_spec.rb
activeadmin-0.6.2 spec/unit/helpers/collection_spec.rb
activeadmin-0.6.1 spec/unit/helpers/collection_spec.rb
aa-rails4-0.6.0 spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.141 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/spec/unit/helpers/collection_spec.rb