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
Original file line numberDiff line numberDiff line change
Expand Up@@ -40,6 +40,8 @@ def self.parse_value(collection, leaf)
return values.map { |item| !%w[false 0 no].include?(item) } if schema.column_type == 'Boolean'

return values.map(&:to_f).select { |item| item.is_a? Numeric } if schema.column_type == 'Number'

return values
end

leaf['value']
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ def self.filterable?(type, supported_operators = [])
def self.get_required_operators(type)
return OPERATOR_BY_TYPE[type] if type.is_a?(String) && OPERATOR_BY_TYPE.key?(type)

return ['Includes_All'] if type.is_a? Array
return [Operators::INCLUDES_ALL] if type.is_a? Array

[]
end
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,7 +35,7 @@ module Charts
review_class = Struct.new(:id, :book_id, :author)
stub_const('Review', review_class)

@datasource = Datasource.new
datasource = Datasource.new
collection_book = instance_double(
Collection,
name: 'book',
Expand DownExpand Up@@ -97,12 +97,14 @@ module Charts
}
)
allow(ForestAdminAgent::Builder::AgentFactory.instance).to receive(:send_schema).and_return(nil)
@datasource.add_collection(collection_book)
@datasource.add_collection(collection_review)
@datasource.add_collection(collection_book_review)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(@datasource)
datasource.add_collection(collection_book)
datasource.add_collection(collection_review)
datasource.add_collection(collection_book_review)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build

@datasource = ForestAdminAgent::Facades::Container.datasource

allow(ForestAdminAgent::Services::Permissions).to receive(:new).and_return(permissions)
allow(permissions).to receive_messages(
can_chart?: true,
Expand DownExpand Up@@ -171,6 +173,7 @@ module Charts
type: 'Value',
timezone: 'Europe/Paris'
})
@datasource.get_collection('book')
allow(@datasource.get_collection('book')).to receive(:aggregate).and_return(
[{ value: 10, group: [] }], # first call
[{ value: 5, group: [] }] # second call
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,18 +24,19 @@ module Resources
let(:permissions) { instance_double(ForestAdminAgent::Services::Permissions) }

before do
@datasource = Datasource.new
collection = Collection.new(@datasource, 'user')
datasource = Datasource.new
collection = Collection.new(datasource, 'user')
allow(collection).to receive(:aggregate).and_return(
[
{ value: 1, group: [] }
]
)
allow(ForestAdminAgent::Builder::AgentFactory.instance).to receive(:send_schema).and_return(nil)

@datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(@datasource)
datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build
@datasource = ForestAdminAgent::Facades::Container.datasource

allow(ForestAdminAgent::Services::Permissions).to receive(:new).and_return(permissions)
allow(permissions).to receive_messages(can?: true, get_scope: nil)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ def respond_to?(arg)
end
stub_const('User', user_class)

@datasource = Datasource.new
datasource = Datasource.new

collection = instance_double(
Collection,
Expand All@@ -63,11 +63,12 @@ def respond_to?(arg)
)

allow(ForestAdminAgent::Builder::AgentFactory.instance).to receive(:send_schema).and_return(nil)
@datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(@datasource)
datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build

@datasource
@datasource = ForestAdminAgent::Facades::Container.datasource
allow(@datasource.get_collection('user')).to receive(:delete)
end

context 'with simple request' do
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ module Resources
user_class = Struct.new(:id, :first_name, :last_name)
stub_const('User', user_class)

@datasource = Datasource.new
datasource = Datasource.new
collection = instance_double(
Collection,
name: 'user',
Expand All@@ -42,9 +42,11 @@ module Resources
list: [User.new(1, 'foo', 'foo')]
)
allow(ForestAdminAgent::Builder::AgentFactory.instance).to receive(:send_schema).and_return(nil)
@datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(@datasource)
datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build
@datasource = ForestAdminAgent::Facades::Container.datasource
allow(@datasource.get_collection('user')).to receive(:list).and_return([User.new(1, 'foo', 'foo')])

allow(ForestAdminAgent::Services::Permissions).to receive(:new).and_return(permissions)
allow(permissions).to receive_messages(can?: true, get_scope: nil)
Expand DownExpand Up@@ -109,8 +111,8 @@ module Resources
{
aggregator: 'And',
conditions: [
{ field: 'id', operator: 'Greater_Than', value: 7 },
{ field: 'first_name', operator: 'Contains', value: 'foo' }
{ field: 'id', operator: 'greater_than', value: 7 },
{ field: 'first_name', operator: 'contains', value: 'foo' }
]
}
)
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ module Related
address_class = Struct.new(:id, :location)
stub_const('Address', address_class)

@datasource = Datasource.new
datasource = Datasource.new
collection_user = instance_double(
Collection,
name: 'user',
Expand DownExpand Up@@ -88,12 +88,14 @@ module Related
)

allow(ForestAdminAgent::Builder::AgentFactory.instance).to receive(:send_schema).and_return(nil)
@datasource.add_collection(collection_user)
@datasource.add_collection(collection_address_user)
@datasource.add_collection(collection_address)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(@datasource)
datasource.add_collection(collection_user)
datasource.add_collection(collection_address_user)
datasource.add_collection(collection_address)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build

@datasource = ForestAdminAgent::Facades::Container.datasource

allow(ForestAdminAgent::Services::Permissions).to receive(:new).and_return(permissions)
allow(permissions).to receive_messages(can?: true, get_scope: nil)
end
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ module Related
include_context 'with caller'
subject(:dissociate) { described_class.new }

let(:datasource) { Datasource.new }
let(:permissions) { instance_double(ForestAdminAgent::Services::Permissions) }

before do
datasource = Datasource.new
collection_user = Collection.new(datasource, 'user')
collection_user.add_fields(
{
Expand DownExpand Up@@ -72,6 +72,8 @@ module Related
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build

@datasource = ForestAdminAgent::Facades::Container.datasource

allow(ForestAdminAgent::Services::Permissions).to receive(:new).and_return(permissions)
allow(permissions).to receive_messages(can?: true, get_scope: nil)
end
Expand DownExpand Up@@ -103,15 +105,15 @@ module Related
end

it 'call dissociate_or_delete_one_to_many without deletion' do
allow(datasource.get_collection('address_user')).to receive(:update).and_return(true)
allow(@datasource.get_collection('address_user')).to receive(:update).and_return(true)

args[:params]['relation_name'] = 'address_users'
args[:params]['data'] = [{ 'id' => 1 }]
args[:params]['id'] = 1

result = dissociate.handle_request(args)

expect(datasource.get_collection('address_user')).to have_received(:update) do |caller, filter, data|
expect(@datasource.get_collection('address_user')).to have_received(:update) do |caller, filter, data|
expect(caller).to be_instance_of(Components::Caller)
expect(filter).to have_attributes(
condition_tree: have_attributes(
Expand All@@ -134,8 +136,8 @@ module Related
end

it 'call dissociate_or_delete_one_to_many with deletion' do
allow(datasource.get_collection('address_user')).to receive(:delete).and_return(true)
allow(datasource.get_collection('address')).to receive(:delete).and_return(true)
allow(@datasource.get_collection('address_user')).to receive(:delete).and_return(true)
allow(@datasource.get_collection('address')).to receive(:delete).and_return(true)

args[:params][:delete] = true
args[:params]['relation_name'] = 'address_users'
Expand All@@ -144,7 +146,7 @@ module Related

result = dissociate.handle_request(args)

expect(datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(@datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(caller).to be_instance_of(Components::Caller)
expect(filter).to have_attributes(
condition_tree: have_attributes(
Expand All@@ -166,8 +168,8 @@ module Related
end

it 'call dissociate_or_delete_one_to_many with deletion on multiple records' do
allow(datasource.get_collection('address_user')).to receive(:delete).and_return(true)
allow(datasource.get_collection('address')).to receive(:delete).and_return(true)
allow(@datasource.get_collection('address_user')).to receive(:delete).and_return(true)
allow(@datasource.get_collection('address')).to receive(:delete).and_return(true)

args[:params][:delete] = true
args[:params]['relation_name'] = 'address_users'
Expand All@@ -181,7 +183,7 @@ module Related

result = dissociate.handle_request(args)

expect(datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(@datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(caller).to be_instance_of(Components::Caller)
expect(filter).to have_attributes(
condition_tree: have_attributes(
Expand DownExpand Up@@ -217,7 +219,7 @@ module Related
end

it 'call dissociate_or_delete_many_to_many without deletion' do
allow(datasource.get_collection('address_user'))
allow(@datasource.get_collection('address_user'))
.to receive_messages(list: [AddressUser.new(1, 1, 1)], delete: true)

args[:params]['relation_name'] = 'addresses'
Expand All@@ -226,7 +228,7 @@ module Related

result = dissociate.handle_request(args)

expect(datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(@datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(caller).to be_instance_of(Components::Caller)
expect(filter).to have_attributes(
condition_tree: have_attributes(
Expand All@@ -248,9 +250,9 @@ module Related
end

it 'call dissociate_or_delete_many_to_many with deletion' do
allow(datasource.get_collection('address_user')).to receive_messages(list: [AddressUser.new(1, 1, 1)],
delete: true)
allow(datasource.get_collection('address')).to receive(:delete).and_return(true)
allow(@datasource.get_collection('address_user')).to receive_messages(list: [AddressUser.new(1, 1, 1)],
delete: true)
allow(@datasource.get_collection('address')).to receive(:delete).and_return(true)

args[:params][:delete] = true
args[:params]['relation_name'] = 'addresses'
Expand All@@ -259,7 +261,7 @@ module Related

result = dissociate.handle_request(args)

expect(datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(@datasource.get_collection('address_user')).to have_received(:delete) do |caller, filter|
expect(caller).to be_instance_of(Components::Caller)
expect(filter).to have_attributes(
condition_tree: have_attributes(
Expand All@@ -277,7 +279,7 @@ module Related
)
end

expect(datasource.get_collection('address')).to have_received(:delete) do |caller, filter|
expect(@datasource.get_collection('address')).to have_received(:delete) do |caller, filter|
expect(caller).to be_instance_of(Components::Caller)
expect(filter).to have_attributes(
condition_tree: have_attributes(
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,7 +29,7 @@ module Related
user_class = Struct.new(:id, :first_name, :last_name)
stub_const('User', user_class)

@datasource = Datasource.new
datasource = Datasource.new
collection_user = instance_double(
Collection,
name: 'user',
Expand DownExpand Up@@ -58,11 +58,13 @@ module Related
}
)
allow(ForestAdminAgent::Builder::AgentFactory.instance).to receive(:send_schema).and_return(nil)
@datasource.add_collection(collection_user)
@datasource.add_collection(collection_category)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(@datasource)
datasource.add_collection(collection_user)
datasource.add_collection(collection_category)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build

@datasource = ForestAdminAgent::Facades::Container.datasource

allow(ForestAdminAgent::Services::Permissions).to receive(:new).and_return(permissions)
allow(permissions).to receive_messages(can?: true, get_scope: Nodes::ConditionTreeBranch.new('Or', []))
end
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,10 +12,10 @@ module Related
include_context 'with caller'
subject(:update) { described_class.new }

let(:datasource) { Datasource.new }
let(:permissions) { instance_double(ForestAdminAgent::Services::Permissions) }

before do
datasource = Datasource.new
collection_user = Collection.new(datasource, 'user')
collection_user.add_fields(
{
Expand DownExpand Up@@ -48,6 +48,7 @@ module Related
datasource.add_collection(collection_book)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build
@datasource = ForestAdminAgent::Facades::Container.datasource

allow(ForestAdminAgent::Services::Permissions).to receive(:new).and_return(permissions)
allow(permissions).to receive_messages(can?: true, get_scope: nil)
Expand DownExpand Up@@ -77,7 +78,7 @@ module Related
end

it 'call handle_request on a many_to_one relation' do
allow(datasource.get_collection('book')).to receive(:update).and_return(true)
allow(@datasource.get_collection('book')).to receive(:update).and_return(true)

args[:params]['collection_name'] = 'book'
args[:params]['relation_name'] = 'author'
Expand All@@ -86,7 +87,7 @@ module Related

result = update.handle_request(args)

expect(datasource.get_collection('book')).to have_received(:update) do |caller, filter, data|
expect(@datasource.get_collection('book')).to have_received(:update) do |caller, filter, data|
expect(caller).to be_instance_of(Components::Caller)
expect(filter).to have_attributes(
condition_tree: have_attributes(field: 'id', operator: Operators::EQUAL, value: 1),
Expand All@@ -102,7 +103,7 @@ module Related
end

it 'call handle_request on a one_to_one relation' do
allow(datasource.get_collection('book')).to receive_messages(aggregate: [{ value: 1 }], update: true)
allow(@datasource.get_collection('book')).to receive_messages(aggregate: [{ value: 1 }], update: true)

args[:params]['collection_name'] = 'user'
args[:params]['relation_name'] = 'book'
Expand DownExpand Up@@ -144,7 +145,7 @@ module Related
]
]

expect(datasource.get_collection('book')).to have_received(:update)
expect(@datasource.get_collection('book')).to have_received(:update)
.exactly(2).times do |caller, filter, data|
parameter = parameters.shift
expect(caller).to be_instance_of(parameter[0])
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ def respond_to?(arg)
end
stub_const('User', user_class)

@datasource = Datasource.new
datasource = Datasource.new

collection = instance_double(
Collection,
Expand All@@ -67,11 +67,11 @@ def respond_to?(arg)
)

allow(ForestAdminAgent::Builder::AgentFactory.instance).to receive(:send_schema).and_return(nil)
@datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(@datasource)
datasource.add_collection(collection)
ForestAdminAgent::Builder::AgentFactory.instance.add_datasource(datasource)
ForestAdminAgent::Builder::AgentFactory.instance.build

@datasource
@datasource = ForestAdminAgent::Facades::Container.datasource
allow(@datasource.get_collection('user')).to receive(:list).and_return([User.new(1, 'foo', 'foo')])
end

it 'return an serialized content' do
Expand Down
Loading