Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.1
3.4.4
6 changes: 3 additions & 3 deletions spec/supplejack/concept_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module Supplejack
it 'requests the concept from the API' do
allow(SupplejackConcept).to receive(:get).with('/concepts/1', {}).and_return('concept' => {})

SupplejackConcept.find(1)
expect(SupplejackConcept.find(1)).not_to be_nil
end

it 'initializes a new SupplejackConcept object' do
Expand All @@ -128,7 +128,7 @@ module Supplejack
allow(Supplejack).to receive(:fields).and_return(%i[verbose default])
allow(SupplejackConcept).to receive(:get).with('/concepts/1', {}).and_return('concept' => {})

SupplejackConcept.find(1)
expect(SupplejackConcept.find(1)).not_to be_nil
end
end
end
Expand All @@ -137,7 +137,7 @@ module Supplejack
it 'calls the get method' do
allow(SupplejackConcept).to receive(:get).with('/concepts', {}).and_return({})

SupplejackConcept.all
expect(SupplejackConcept.all).not_to be_nil
end
end
end
Expand Down
20 changes: 10 additions & 10 deletions spec/supplejack/controllers/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Controllers
controller.search
end

it 'tries to initialize with params[:search] ' do
it 'tries to initialize with params[:search]' do
allow(controller).to receive(:params).and_return({ search: { text: 'cat' } })

expect(Supplejack::Search).to receive(:new).with({ text: 'cat' })
Expand Down Expand Up @@ -100,7 +100,7 @@ module Controllers
it 'correctly uses the translation for the label' do
allow(I18n).to receive(:t).with('supplejack_user_sets.user.name', default: 'User.name').and_return('By')

controller.attribute(user_set, 'user.name')
expect(controller.attribute(user_set, 'user.name')).not_to be_nil
end
end

Expand Down Expand Up @@ -132,11 +132,11 @@ module Controllers
end

it 'doesn\'t display content_partner' do
expect(controller.attribute(record, :content_partner)).to be nil
expect(controller.attribute(record, :content_partner)).to be_nil
end

it 'doesn\'t display description' do
expect(controller.attribute(record, :description)).to be nil
expect(controller.attribute(record, :description)).to be_nil
end

it 'displays span label tag' do
Expand All @@ -150,7 +150,7 @@ module Controllers
it 'uses the translation key' do
allow(I18n).to receive(:t).with('item.key', default: 'Title').and_return('Title')

controller.attribute(record, :title, trans_key: 'item.key')
expect(controller.attribute(record, :title, trans_key: 'item.key')).not_to be_nil
end

context 'when :link => true' do
Expand All @@ -175,14 +175,14 @@ module Controllers
end

it 'returns nothing when value is nil' do
expect(controller.attribute(record, :description, link: true)).to be nil
expect(controller.attribute(record, :description, link: true)).to be_nil
end
end

it 'returns nothing when value is "Not specified"' do
record = mock_record(description: 'Not specified')

expect(controller.attribute(record, :description)).to be nil
expect(controller.attribute(record, :description)).to be_nil
end

it 'adds extra_html inside of the <p>' do
Expand Down Expand Up @@ -265,7 +265,7 @@ module Controllers
end

it 'returns nothing when both values are nil' do
expect(controller.attribute(record, %i[object_url source], link: true)).to be nil
expect(controller.attribute(record, %i[object_url source], link: true)).to be_nil
end
end
end
Expand Down Expand Up @@ -298,8 +298,8 @@ module Controllers
end

it 'displays the next and previous links' do
allow(controller).to receive(:previous_record_link).and_return('<a class="prev" href="/records/37674826?search%5Bpath%5D=items&amp;search%5Btext%5D=Forest+fire">Previous result</a>')
allow(controller).to receive(:next_record_link).and_return('<a class="next" href="/records/37674826?search%5Bpath%5D=items&amp;search%5Btext%5D=Forest+fire">Next result</a>')
allow(controller).to receive_messages(previous_record_link: '<a class="prev" href="/records/37674826?search%5Bpath%5D=items&amp;search%5Btext%5D=Forest+fire">Previous result</a>',
next_record_link: '<a class="next" href="/records/37674826?search%5Bpath%5D=items&amp;search%5Btext%5D=Forest+fire">Next result</a>')

expect(controller.next_previous_links(record)).to eq %(<span class=\"nav\">&lt;a class=&quot;next&quot; href=&quot;/records/37674826?search%5Bpath%5D=items&amp;amp;search%5Btext%5D=Forest+fire&quot;&gt;Next result&lt;/a&gt;</span>)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/supplejack/item_relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ module Supplejack
allow(relation).to receive(:build).and_return(item)
expect(item).to receive(:save)

relation.create
expect(relation.create).not_to be_nil
end

it 'passes the parameters along to the build method' do
allow(relation).to receive(:build).with({ record_id: 8, position: 3 }).and_return(item)

relation.create({ record_id: 8, position: 3 })
expect(relation.create({ record_id: 8, position: 3 })).not_to be_nil
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/supplejack/item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ module Supplejack
it 'returns nil when the date is not in the correct format' do
item = described_class.new(date: ['afsdfgsdfg'])

expect(item.date).to be nil
expect(item.date).to be_nil
end
end

describe '#method_missing' do
it 'returns nil for any unknown attribute' do
expect(described_class.new.non_existent_method).to be nil
expect(described_class.new.non_existent_method).to be_nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/supplejack/log_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Supplejack
it 'returns nil when logging not enabled' do
allow(Supplejack).to receive(:enable_logging).and_return(false)

expect(described_class.new.log_request(1, {})).to be nil
expect(described_class.new.log_request(1, {})).to be_nil
end
end
end
2 changes: 1 addition & 1 deletion spec/supplejack/more_like_this_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module Supplejack
{ 'more_like_this' => { 'record' => {} } }
)

more_like_this.records
expect(more_like_this.records).not_to be_nil
end

context 'when record not found' do
Expand Down
2 changes: 1 addition & 1 deletion spec/supplejack/paginated_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
it { expect(collection.total_pages).to eq 2 }
it { expect(collection.current_page).to eq 1 }
it { expect(collection.per_page).to eq 10 }
it { expect(collection.previous_page).to be nil }
it { expect(collection.previous_page).to be_nil }
it { expect(collection.next_page).to eq 2 }
it { expect(collection.out_of_bounds?).not_to be true }
it { expect(collection.offset).to eq 0 }
Expand Down
18 changes: 9 additions & 9 deletions spec/supplejack/record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ module Supplejack
it 'requests the record from the API' do
allow(SupplejackRecord).to receive(:get).with('/records/1', { fields: 'default' }).and_return({ 'record' => {} })

SupplejackRecord.find(1)
expect(SupplejackRecord.find(1)).not_to be_nil
end

it 'initializes a new SupplejackRecord object' do
Expand All @@ -203,13 +203,13 @@ module Supplejack
allow(Supplejack).to receive(:fields).and_return(%i[verbose default])
allow(SupplejackRecord).to receive(:get).with('/records/1', { fields: 'verbose,default' }).and_return({ 'record' => {} })

SupplejackRecord.find(1)
expect(SupplejackRecord.find(1)).not_to be_nil
end

it 'sets the correct search options' do
allow(SupplejackRecord).to receive(:get).with('/records/1', hash_including(search: hash_including({ text: 'dog' }))).and_return({ 'record' => {} })

SupplejackRecord.find(1, text: 'dog')
expect(SupplejackRecord.find(1, text: 'dog')).not_to be_nil
end

context 'when using a special search klass' do
Expand All @@ -220,29 +220,29 @@ module Supplejack
allow(Supplejack).to receive(:search_klass).and_return('Search')
allow(::Search).to receive(:new).with({ i: { location: 'Wellington' } }).and_return(search)

SupplejackRecord.find(1, i: { location: 'Wellington' })
expect(SupplejackRecord.find(1, { i: { location: 'Wellington' } })).not_to be_nil
end

it 'uses the default search klass' do
allow(SupplejackRecord).to receive(:get).and_return({ 'record' => {} })
allow(Supplejack).to receive(:search_klass).and_return(nil)
allow(Supplejack::Search).to receive(:new).with({ i: { location: 'Wellington' } }).and_return(search)

SupplejackRecord.find(1, { i: { location: 'Wellington' } })
expect(SupplejackRecord.find(1, { i: { location: 'Wellington' } })).not_to be_nil
end

it 'sends the params from the subclassed search to the API' do
allow(Supplejack).to receive(:search_klass).and_return('Search')
allow(SupplejackRecord).to receive(:get).with('/records/1', hash_including(search: hash_including({ and: { name: 'John' }, or: { type: ['Person'] } }))).and_return('record' => {})

SupplejackRecord.find(1, i: { name: 'John' })
expect(SupplejackRecord.find(1, { i: { name: 'John' } })).not_to be_nil
end

it 'sends any changes to the api_params made on the subclassed search object' do
allow(Supplejack).to receive(:search_klass).and_return('SpecialSearch')
allow(SupplejackRecord).to receive(:get).with('/records/1', hash_including(search: hash_including(and: {}))).and_return('record' => {})

SupplejackRecord.find(1, i: { format: 'Images' })
expect(SupplejackRecord.find(1, { i: { format: 'Images' } })).not_to be_nil
end
end
end
Expand All @@ -251,7 +251,7 @@ module Supplejack
it 'sends a request to /records/multiple endpoint with an array of record ids' do
allow(SupplejackRecord).to receive(:get).with('/records/multiple', { record_ids: [1, 2], fields: 'default' }).and_return({ 'records' => [] })

SupplejackRecord.find([1, 2])
expect(SupplejackRecord.find([1, 2])).not_to be_nil
end

it 'initializes multiple SupplejackRecord objects' do
Expand All @@ -266,7 +266,7 @@ module Supplejack
allow(Supplejack).to receive(:fields).and_return(%i[verbose description])
allow(SupplejackRecord).to receive(:get).with('/records/multiple', { record_ids: [1, 2], fields: 'verbose,description' }).and_return({ 'records' => [] })

SupplejackRecord.find([1, 2])
expect(SupplejackRecord.find([1, 2])).not_to be_nil
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions spec/supplejack/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ module Supplejack
subject(:requester) { Supplejack::TestClass.new }

before do
allow(Supplejack).to receive(:api_key).and_return('123')
allow(Supplejack).to receive(:api_url).and_return('http://api.org')
allow(Supplejack).to receive(:timeout).and_return(20)
allow(Supplejack).to receive_messages(api_key: '123', api_url: 'http://api.org', timeout: 20)
end

describe '#get' do
Expand Down
34 changes: 17 additions & 17 deletions spec/supplejack/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module Supplejack
end

it 'returns nil when not set' do
expect(described_class.new.sort).to be nil
expect(described_class.new.sort).to be_nil
end
end

Expand All @@ -85,7 +85,7 @@ module Supplejack
end

it 'returns nil when not set' do
expect(described_class.new.direction).to be nil
expect(described_class.new.direction).to be_nil
end
end

Expand Down Expand Up @@ -179,14 +179,14 @@ module Supplejack
it 'returns nil when facet is not found' do
allow(search).to receive(:facets).and_return([])

expect(search.facet('collection')).to be nil
expect(search.facet('collection')).to be_nil
end

it 'returns nil if value is nil' do
facet = Supplejack::Facet.new('collection', [])
allow(search).to receive(:facets) { [facet] }

expect(search.facet(nil)).to be nil
expect(search.facet(nil)).to be_nil
end
end

Expand Down Expand Up @@ -239,13 +239,13 @@ module Supplejack
end

describe '#results' do
let(:search) { described_class.new }
let(:record1) { { 'id' => 1, 'title' => 'Wellington' } }
let(:record2) { { 'id' => 2, 'title' => 'Auckland' } }
let(:search) { described_class.new }
let(:recordone) { { 'id' => 1, 'title' => 'Wellington' } }
let(:recordtwo) { { 'id' => 2, 'title' => 'Auckland' } }

before do
allow(Supplejack).to receive(:record_klass).and_return('TestRecord')
search.instance_variable_set(:@response, 'search' => { 'result_count' => 2, 'results' => [record1, record2] })
search.instance_variable_set(:@response, 'search' => { 'result_count' => 2, 'results' => [recordone, recordtwo] })
end

it 'executes the request only once' do
Expand All @@ -264,18 +264,18 @@ module Supplejack
end

it 'initializes record objects with the default class' do
expect(TestRecord).to receive(:new).with(record1)
expect(TestRecord).to receive(:new).with(record2)
expect(TestRecord).to receive(:new).with(recordone)
expect(TestRecord).to receive(:new).with(recordtwo)

search.results
end

it 'initializes record objects with the class provided in the params' do
search = described_class.new(record_klass: 'test_item')
search.instance_variable_set(:@response, 'search' => { 'results' => [record1, record2] })
search.instance_variable_set(:@response, 'search' => { 'results' => [recordone, recordtwo] })

expect(TestItem).to receive(:new).with(record1)
expect(TestItem).to receive(:new).with(record2)
expect(TestItem).to receive(:new).with(recordone)
expect(TestItem).to receive(:new).with(recordtwo)

search.results
end
Expand Down Expand Up @@ -580,7 +580,7 @@ module Supplejack
it 'returns false when location has nil value' do
search.location = nil

expect(search.has_category?('Cats')).to be nil
expect(search.has_category?('Cats')).to be_nil
end

it 'search for onlu existent search attribute' do
Expand Down Expand Up @@ -608,10 +608,10 @@ module Supplejack
it 'removes category filter from the search request' do
allow(search).to receive(:get).with('/records', hash_including(and: { year: 2001 })).and_return('search' => { 'facets' => { 'category' => { 'Books' => 123 } } })

search.categories
expect(search.categories).not_to be_nil
end

it 'returns the category facet hash ' do
it 'returns the category facet hash' do
expect(search.categories).to include('Books' => 123)
end

Expand Down Expand Up @@ -653,7 +653,7 @@ module Supplejack
expect(search.fetch_facet_values('category')['All']).to eq 223
end

it 'doesnt return the All count ' do
it 'doesnt return the All count' do
expect(search.fetch_facet_values('category', all: false)).not_to have_key('All')
end

Expand Down
4 changes: 2 additions & 2 deletions spec/supplejack/story_item_relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ module Supplejack
it 'passes the parameters along to the build method' do
allow(relation).to receive(:build).with({ type: 'embed' }).and_return(item)

relation.create({ type: 'embed' })
expect(relation.create({ type: 'embed' })).not_to be_nil
end
end

context 'when items are arrays' do
it 'executes array methods on the @items array' do
expect(relation.any? { |x| x.id == 1 }).to eq(true)
expect(relation.any? { |x| x.id == 1 }).to be(true)
end

it 'iterates through the items relation' do
Expand Down
Loading