Skip to content

Commit

Permalink
update search_spec to cover query_params scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor authored and cbeer committed Jul 13, 2022
1 parent f820da4 commit b0c7286
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions spec/models/search_spec.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
# frozen_string_literal: true

RSpec.describe Search do
let(:search) { described_class.new(user: user) }
let(:user) { User.create! email: '[email protected]', password: 'xyz12345' }
let(:hash_params) { { q: "query", f: { facet: "filter" } } }
let(:query_params) { hash_params }

describe "query_params" do
before do
@search = described_class.new(user: user)
@query_params = { q: "query", f: "facet" }
shared_examples "persisting query_params" do
it "can save and retrieve the hash" do
search.query_params = query_params
search.save!
expect(described_class.find(search.id).query_params).to eq query_params.with_indifferent_access
end
end

it "can save and retrieve the hash" do
@search.query_params = @query_params
@search.save!
expect(described_class.find(@search.id).query_params).to eq @query_params
context "are an indifferent hash" do
include_context "persisting query_params" do
let(:query_params) { hash_params.with_indifferent_access }
end
end

context "are a string-keyed hash" do
include_context "persisting query_params" do
let(:query_params) { hash_params.with_indifferent_access.to_hash }
end
end

context "include symbol keys" do
include_context "persisting query_params" do
let(:query_params) { hash_params }
end
end
end

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

expect(@search).to be_saved
search.save!
expect(search).to be_saved
end

it "is false when user_id is NULL or less than 1" do
@search = described_class.create
expect(@search).not_to be_saved
context "when user_id is NULL or less than 1" do
let(:search) { described_class.create }

it "is false" do
expect(search).not_to be_saved
end
end
end

Expand Down

0 comments on commit b0c7286

Please sign in to comment.