Sha256: b7fc16810397d29a3e631809d5ee5a66b210acab06f731f26b9e91ba5bc7bda6

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require File.expand_path('../spec_helper', File.dirname(__FILE__))

describe WillFilter::ActiveRecordExtension do
  describe '#filter' do
    before :all do
      5.times {|i| User.create(:first_name => "User #{i}")}
    end

    context "filtering with no params" do
      it "should return all of the results" do
        User.filter(:params => {}).total_count.should == User.count
      end
    end

    context "filtering with is operator" do
      it "should return a single result" do
        User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "is", :wf_v0_0 => "User 1"}).total_count.should == 1
      end
    end
    
    context "filtering with like operator" do
      it "should return all matched results" do
        User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "contains", :wf_v0_0 => "User"}).total_count.should == User.count
      end
    end
    
    context "filtering with ends_with operator" do
      it "should return all matched results" do
        User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "ends_with", :wf_v0_0 => "4"}).total_count.should == 1
      end
    end

    context "filtering with starts_with operator" do
      it "should return all matched results" do
        User.filter(:params => {:wf_c0 => "first_name", :wf_o0 => "starts_with", :wf_v0_0 => "U"}).total_count.should == User.count
      end
    end
    
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
will_filter-3.1.7 spec/extensions/active_record_extension_spec.rb
will_filter-3.1.6 spec/extensions/active_record_extension_spec.rb
will_filter-3.1.5 spec/extensions/active_record_extension_spec.rb
will_filter-3.1.3 spec/extensions/active_record_extension_spec.rb