Skip to content

Commit

Permalink
Merge pull request #140 from RestPack/gj/upgrade-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
GavinJoyce authored Nov 24, 2016
2 parents ba52c7a + b3117c1 commit 42e472b
Show file tree
Hide file tree
Showing 19 changed files with 326 additions and 301 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
tmp
/coverage
Gemfile.lock
/.idea
19 changes: 10 additions & 9 deletions restpack_serializer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]

gem.add_dependency 'activesupport', ['>= 4.0.3', '< 5.0']
gem.add_dependency 'activerecord', ['>= 4.0.3', '< 5.0']
gem.add_dependency 'kaminari', '~> 0.16.1'
gem.add_dependency 'activesupport', ['>= 4.0.3', '< 6.0']
gem.add_dependency 'activerecord', ['>= 4.0.3', '< 6.0']
gem.add_dependency 'kaminari', '~> 0.17.0'
gem.add_dependency 'kaminari-mongoid', '~> 0.1'

gem.add_development_dependency 'restpack_gem', '~> 0.0.9'
gem.add_development_dependency 'rake', '~> 11.1.2'
gem.add_development_dependency 'guard-rspec', '~> 4.6.4'
gem.add_development_dependency 'factory_girl', '~> 4.7.0'
gem.add_development_dependency 'sqlite3', '~> 1.3.7'
gem.add_development_dependency 'database_cleaner', '~> 1.5.3'
gem.add_development_dependency 'rake', '~> 11.3'
gem.add_development_dependency 'guard-rspec', '~> 4.7'
gem.add_development_dependency 'factory_girl', '~> 4.7'
gem.add_development_dependency 'sqlite3', '~> 1.3'
gem.add_development_dependency 'database_cleaner', '~> 1.5'
gem.add_development_dependency 'rspec'
gem.add_development_dependency 'bump'
gem.add_development_dependency 'protected_attributes', '~> 1.1.3'
gem.add_development_dependency 'protected_attributes_continued', '~> 1.2'
end
35 changes: 21 additions & 14 deletions spec/factory/factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,52 @@

describe "single-word" do
it "creates by string" do
factory.create("Song").should be_an_instance_of(MyApp::SongSerializer)
expect(factory.create("Song")).to be_an_instance_of(MyApp::SongSerializer)
end

it "creates by lowercase string" do
factory.create("song").should be_an_instance_of(MyApp::SongSerializer)
expect(factory.create("song")).to be_an_instance_of(MyApp::SongSerializer)
end

it "creates by lowercase plural string" do
factory.create("songs").should be_an_instance_of(MyApp::SongSerializer)
expect(factory.create("songs")).to be_an_instance_of(MyApp::SongSerializer)
end

it "creates by symbol" do
factory.create(:song).should be_an_instance_of(MyApp::SongSerializer)
expect(factory.create(:song)).to be_an_instance_of(MyApp::SongSerializer)
end

it "creates by class" do
factory.create(MyApp::Song).should be_an_instance_of(MyApp::SongSerializer)
expect(factory.create(MyApp::Song)).to be_an_instance_of(MyApp::SongSerializer)
end

it "creates multiple with Array" do
serializers = factory.create("Song", "artists", :album)
serializers[0].should be_an_instance_of(MyApp::SongSerializer)
serializers[1].should be_an_instance_of(MyApp::ArtistSerializer)
serializers[2].should be_an_instance_of(MyApp::AlbumSerializer)
expect(serializers[0]).to be_an_instance_of(MyApp::SongSerializer)
expect(serializers[1]).to be_an_instance_of(MyApp::ArtistSerializer)
expect(serializers[2]).to be_an_instance_of(MyApp::AlbumSerializer)
end
end

describe "multi-word" do
it "creates multi-word string" do
factory.create("AlbumReview").should be_an_instance_of(MyApp::AlbumReviewSerializer)
expect(factory.create("AlbumReview")).to be_an_instance_of(MyApp::AlbumReviewSerializer)
end

it "creates multi-word lowercase string" do
factory.create("album_review").should be_an_instance_of(MyApp::AlbumReviewSerializer)
expect(factory.create("album_review")).to be_an_instance_of(MyApp::AlbumReviewSerializer)
end

it "creates multi-word lowercase plural string" do
factory.create("album_reviews").should be_an_instance_of(MyApp::AlbumReviewSerializer)
expect(factory.create("album_reviews")).to be_an_instance_of(MyApp::AlbumReviewSerializer)
end

it "creates multi-word symbol" do
factory.create(:album_review).should be_an_instance_of(MyApp::AlbumReviewSerializer)
expect(factory.create(:album_review)).to be_an_instance_of(MyApp::AlbumReviewSerializer)
end

it "creates multi-word class" do
factory.create(MyApp::AlbumReview).should be_an_instance_of(MyApp::AlbumReviewSerializer)
expect(factory.create(MyApp::AlbumReview)).to be_an_instance_of(MyApp::AlbumReviewSerializer)
end
end

end
2 changes: 1 addition & 1 deletion spec/fixtures/db.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'sqlite3'
require 'active_record'
require 'protected_attributes'
require 'protected_attributes_continued'

ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
Expand Down
8 changes: 4 additions & 4 deletions spec/restpack_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

context "#setup" do
it "has defaults" do
subject.config.href_prefix.should == ''
subject.config.page_size.should == 10
expect(subject.config.href_prefix).to eq('')
expect(subject.config.page_size).to eq(10)
end

it "can be configured" do
Expand All @@ -16,8 +16,8 @@
config.page_size = 50
end

subject.config.href_prefix.should == '/api/v1'
subject.config.page_size.should == 50
expect(subject.config.href_prefix).to eq('/api/v1')
expect(subject.config.page_size).to eq(50)
end
end
end
31 changes: 16 additions & 15 deletions spec/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
describe RestPack::Serializer::Result do
context 'a new instance' do
it 'has defaults' do
subject.resources.should == {}
subject.meta.should == {}
subject.links.should == {}
expect(subject.resources).to eq({})
expect(subject.meta).to eq({})
expect(subject.links).to eq({})
end
end

context 'when serializing' do
let(:result) { subject.serialize }

context 'in jsonapi.org format' do
context 'an empty result' do
it 'returns an empty result' do
result.should == {}
expect(result).to eq({})
end
end

Expand All @@ -26,9 +27,9 @@
end

it 'returns correct jsonapi.org format' do
result[:albums].should == subject.resources[:albums]
result[:meta].should == subject.meta
result[:links].should == subject.links
expect(result[:albums]).to eq(subject.resources[:albums])
expect(result[:meta]).to eq(subject.meta)
expect(result[:links]).to eq(subject.links)
end
end

Expand All @@ -43,16 +44,16 @@
end

it 'returns correct jsonapi.org format, including injected has_many links' do
result[:albums].should == [{ id: '1', name: 'AMOK', links: { songs: ['91'] } }]
result[:links].should == subject.links
result[:linked][:songs].should == subject.resources[:songs]
expect(result[:albums]).to eq([{ id: '1', name: 'AMOK', links: { songs: ['91'] } }])
expect(result[:links]).to eq(subject.links)
expect(result[:linked][:songs]).to eq(subject.resources[:songs])
end

it 'includes resources in correct order' do
result.keys[0].should == :albums
result.keys[1].should == :linked
result.keys[2].should == :links
result.keys[3].should == :meta
expect(result.keys[0]).to eq(:albums)
expect(result.keys[1]).to eq(:linked)
expect(result.keys[2]).to eq(:links)
expect(result.keys[3]).to eq(:meta)
end

context 'with multiple calls to serialize' do
Expand All @@ -62,7 +63,7 @@
end

it 'does not create duplicate has_many links' do
result[:albums].first[:links][:songs].count.should == 1
expect(result[:albums].first[:links][:songs].count).to eq(1)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/serializable/filterable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class CustomSerializer
end

it "captures the specified filters" do
CustomSerializer.serializable_filters.should == [:a, :c]
expect(CustomSerializer.serializable_filters).to eq([:a, :c])
end
end
75 changes: 40 additions & 35 deletions spec/serializable/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,94 +6,99 @@
let(:scope) { nil }

describe 'default values' do
it { subject.model_class.should == MyApp::Song }
it { subject.include.should == [] }
it { subject.page.should == 1 }
it { subject.page_size.should == 10 }
it { subject.filters.should == {} }
it { subject.scope.should == MyApp::Song.all }
it { subject.default_page_size?.should == true }
it { subject.filters_as_url_params.should == '' }
it { expect(subject.model_class).to eq(MyApp::Song) }
it { expect(subject.include).to eq([]) }
it { expect(subject.page).to eq(1) }
it { expect(subject.page_size).to eq(10) }
it { expect(subject.filters).to eq({}) }
it { expect(subject.scope).to eq(MyApp::Song.all) }
it { expect(subject.default_page_size?).to eq(true) }
it { expect(subject.filters_as_url_params).to eq('') }
end

describe 'with paging params' do
let(:params) { { 'page' => '2', 'page_size' => '8' } }
it { subject.page.should == 2 }
it { subject.page_size.should == 8 }
it { expect(subject.page).to eq(2) }
it { expect(subject.page_size).to eq(8) }
end

describe 'with include' do
let(:params) { { 'include' => 'model1,model2' } }
it { subject.include.should == ["model1", "model2"] }
it { expect(subject.include).to eq(%w(model1 model2)) }
end

context 'with filters' do
describe 'with no filter params' do
let(:params) { { } }
it { subject.filters.should == {} }
let(:params) { {} }
it { expect(subject.filters).to eq({}) }
end

describe 'with a primary key with a single value' do
let(:params) { { 'id' => '142857' } }
it { subject.filters.should == { id: ['142857'] } }
it { subject.filters_as_url_params.should == 'id=142857' }
it { expect(subject.filters).to eq(id: %w(142857)) }
it { expect(subject.filters_as_url_params).to eq('id=142857') }
end

describe 'with a primary key with multiple values' do
let(:params) { { 'ids' => '42,142857' } }
it { subject.filters.should == { id: ['42', '142857'] } }
it { subject.filters_as_url_params.should == 'id=42,142857' }
it { expect(subject.filters).to eq(id: %w(42 142857)) }
it { expect(subject.filters_as_url_params).to eq('id=42,142857') }
end

describe 'with a foreign key with a single value' do
let(:params) { { 'album_id' => '789' } }
it { subject.filters.should == { album_id: ['789'] } }
it { subject.filters_as_url_params.should == 'album_id=789' }
it { expect(subject.filters).to eq(album_id: %w(789)) }
it { expect(subject.filters_as_url_params).to eq('album_id=789') }
end

describe 'with a foreign key with multiple values' do
let(:params) { { 'album_id' => '789,678,567' } }
it { subject.filters.should == { album_id: ['789', '678', '567'] } }
it { subject.filters_as_url_params.should == 'album_id=789,678,567' }
it { expect(subject.filters).to eq(album_id: %w(789 678 567)) }
it { expect(subject.filters_as_url_params).to eq('album_id=789,678,567') }
end

describe 'with multiple foreign keys' do
let(:params) { { 'album_id' => '111,222', 'artist_id' => '888,999' } }
it { subject.filters.should == { album_id: ['111', '222'], artist_id: ['888', '999'] } }
it { subject.filters_as_url_params.should == 'album_id=111,222&artist_id=888,999' }
it { expect(subject.filters).to eq(album_id: %w(111 222), artist_id: %w(888 999)) }
it { expect(subject.filters_as_url_params).to eq('album_id=111,222&artist_id=888,999') }
end
end

context 'with sorting parameters' do
describe 'with no params' do
let(:params) { { } }
it { subject.sorting.should == {} }
let(:params) { {} }
it { expect(subject.sorting).to eq({}) }
end
describe 'with a sorting value' do
let(:params) { { 'sort' => 'Title' } }
it { subject.sorting.should == { title: :asc } }
it { subject.sorting_as_url_params.should == 'sort=title' }
it { expect(subject.sorting).to eq(title: :asc) }
it { expect(subject.sorting_as_url_params).to eq('sort=title') }
end
describe 'with a descending sorting value' do
let(:params) { { 'sort' => '-title' } }
it { subject.sorting.should == { title: :desc } }
it { subject.sorting_as_url_params.should == 'sort=-title' }
it { expect(subject.sorting).to eq(title: :desc) }
it { expect(subject.sorting_as_url_params).to eq('sort=-title') }
end
describe 'with multiple sorting values' do
let(:params) { { 'sort' => '-Title,ID' } }
it { subject.sorting.should == { title: :desc, id: :asc } }
it { subject.sorting_as_url_params.should == 'sort=-title,id' }
it { expect(subject.sorting).to eq(title: :desc, id: :asc) }
it { expect(subject.sorting_as_url_params).to eq('sort=-title,id') }
end
describe 'with a not allowed sorting value' do
let(:params) { { 'sort' => '-title,album_id,id' } }
it { subject.sorting.should == { title: :desc, id: :asc } }
it { subject.sorting_as_url_params.should == 'sort=-title,id' }
it { expect(subject.sorting).to eq(title: :desc, id: :asc) }
it { expect(subject.sorting_as_url_params).to eq('sort=-title,id') }
end
end

context 'scopes' do
describe 'with default scope' do
it { subject.scope.should == MyApp::Song.all }
it { expect(subject.scope).to eq(MyApp::Song.all) }
end

describe 'with custom scope' do
let(:scope) { MyApp::Song.where("id >= 100") }
it { subject.scope.should == scope }
it { expect(subject.scope).to eq(scope) }
end
end
end
Loading

0 comments on commit 42e472b

Please sign in to comment.