Sha256: ea6332528892f2e42d1f8bb38da2f37014e6ae4cf3bebcdb634ef4e4463ba3f4

Contents?: true

Size: 1.73 KB

Versions: 35

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

describe Search do
  let(:user) { User.create! email: 'xyz@example.com', password: 'xyz12345'}
  describe "query_params" do
    before(:each) do
      @search = Search.new(user: user)
      @query_params = { :q => "query", :f => "facet" }
    end

    it "can save and retrieve the hash" do
      @search.query_params = @query_params
      @search.save!
      expect(Search.find(@search.id).query_params).to eq @query_params
    end
  end

  describe "saved?" do
    it "is true when user_id is not NULL and greater than 0" do
      @search = Search.new(user: user)
      @search.save!

      expect(@search).to be_saved
    end
    it "is false when user_id is NULL or less than 1" do
      @search = Search.create
      expect(@search).not_to be_saved
    end
  end

  describe "delete_old_searches" do
    it "throws an ArgumentError if days_old is not a number" do
      expect { Search.delete_old_searches("blah") }.to raise_error(ArgumentError)
    end

    it "throws an ArgumentError if days_old is equal to 0" do
      expect { Search.delete_old_searches(0) }.to raise_error(ArgumentError)
    end

    it "throws an ArgumentError if days_old is less than 0" do
      expect { Search.delete_old_searches(-1) }.to raise_error(ArgumentError)
    end

    it "destroy searches with no user_id that are older than X days" do
      Search.destroy_all
      days_old = 7
      Search.create!(created_at: Date.today)
      Search.create!(created_at: Date.today - (days_old + 1).days)
      Search.create!(user: user, created_at: Date.today)
      Search.create!(user: user, created_at: Date.today - (days_old + 1).days)

      expect do
        Search.delete_old_searches(days_old)
      end.to change(Search, :count).by(-1)
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
blacklight-6.24.0 spec/models/search_spec.rb
blacklight-6.23.0 spec/models/search_spec.rb
blacklight-6.22.0 spec/models/search_spec.rb
blacklight-6.21.0 spec/models/search_spec.rb
blacklight-6.20.0 spec/models/search_spec.rb
blacklight-6.19.2 spec/models/search_spec.rb
blacklight-6.19.1 spec/models/search_spec.rb
blacklight-6.19.0 spec/models/search_spec.rb
blacklight-6.18.0 spec/models/search_spec.rb
blacklight-6.17.0 spec/models/search_spec.rb
blacklight-6.16.0 spec/models/search_spec.rb
blacklight-6.15.0 spec/models/search_spec.rb
blacklight-6.14.1 spec/models/search_spec.rb
blacklight-6.14.0 spec/models/search_spec.rb
blacklight-6.13.0 spec/models/search_spec.rb
blacklight-6.12.0 spec/models/search_spec.rb
blacklight-6.11.2 spec/models/search_spec.rb
blacklight-6.11.1 spec/models/search_spec.rb
blacklight-6.11.0 spec/models/search_spec.rb
blacklight-6.10.1 spec/models/search_spec.rb