mirror of
https://github.com/samsonjs/grape-active_model_serializers.git
synced 2026-04-27 14:57:43 +00:00
Add Sequel integration spec.
This commit is contained in:
parent
ed5d5b4ca4
commit
eb28eb2636
3 changed files with 71 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
### 1.5.1 (Next)
|
### 1.5.1 (Next)
|
||||||
|
|
||||||
* Your contribution here.
|
* Your contribution here.
|
||||||
|
* [#74](https://github.com/ruby-grape/grape-active_model_serializers/pull/74): Add support for Sequel - [@drn](https://github.com/drn).
|
||||||
* [#65](https://github.com/ruby-grape/grape-active_model_serializers/pull/65): Added Danger, PR linter - [@dblock](https://github.com/dblock).
|
* [#65](https://github.com/ruby-grape/grape-active_model_serializers/pull/65): Added Danger, PR linter - [@dblock](https://github.com/dblock).
|
||||||
* [#63](https://github.com/ruby-grape/grape-active_model_serializers/pull/63): Pass adapter options through render - [@drn](https://github.com/drn).
|
* [#63](https://github.com/ruby-grape/grape-active_model_serializers/pull/63): Pass adapter options through render - [@drn](https://github.com/drn).
|
||||||
|
|
||||||
|
|
|
||||||
2
Gemfile
2
Gemfile
|
|
@ -10,5 +10,7 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
|
gem 'sqlite3'
|
||||||
|
gem 'sequel', '~> 4.37', require: false
|
||||||
gem 'ruby-grape-danger', '~> 0.1.0', require: false
|
gem 'ruby-grape-danger', '~> 0.1.0', require: false
|
||||||
end
|
end
|
||||||
|
|
|
||||||
68
spec/integration/sequel_spec.rb
Normal file
68
spec/integration/sequel_spec.rb
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
require 'sequel'
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'Sequel Integration' do
|
||||||
|
before do
|
||||||
|
DB = Sequel.sqlite unless defined?(DB)
|
||||||
|
DB.create_table(:users) do
|
||||||
|
primary_key :id
|
||||||
|
String :name
|
||||||
|
end
|
||||||
|
ActiveModelSerializers.config.adapter = :json
|
||||||
|
app.format :json
|
||||||
|
app.formatter :json, Grape::Formatter::ActiveModelSerializers
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
DB.drop_table(:users)
|
||||||
|
Object.send(:remove_const, :SequelUser)
|
||||||
|
Object.send(:remove_const, :SequelUserSerializer)
|
||||||
|
end
|
||||||
|
|
||||||
|
let!(:model) {
|
||||||
|
SequelUser = Class.new(Sequel::Model(:users)) do
|
||||||
|
include ActiveModel::Serialization
|
||||||
|
def self.model_name
|
||||||
|
'User'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
}
|
||||||
|
let!(:serializer) {
|
||||||
|
SequelUserSerializer = Class.new(ActiveModel::Serializer) do
|
||||||
|
attributes :id, :name
|
||||||
|
end
|
||||||
|
}
|
||||||
|
let(:app) { Class.new(Grape::API) }
|
||||||
|
|
||||||
|
context 'collection' do
|
||||||
|
let!(:users) {
|
||||||
|
[
|
||||||
|
model.create(name: 'one'),
|
||||||
|
model.create(name: 'two')
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
it 'renders' do
|
||||||
|
app.get('/users') { render SequelUser.dataset }
|
||||||
|
response = get '/users'
|
||||||
|
expect(JSON.parse(response.body)).to eq(
|
||||||
|
'users' => [
|
||||||
|
{ 'id' => 1, 'name' => 'one' },
|
||||||
|
{ 'id' => 2, 'name' => 'two' }
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'member' do
|
||||||
|
let!(:user) { model.create(name: 'name') }
|
||||||
|
|
||||||
|
it 'renders' do
|
||||||
|
app.get('/user/1') { render SequelUser.first }
|
||||||
|
response = get '/user/1'
|
||||||
|
expect(JSON.parse(response.body)).to eq(
|
||||||
|
'user' => { 'id' => 1, 'name' => 'name' }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue