mno-enterprise-core 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/models/mno_enterprise/base_resource.rb +2 -1
- data/app/models/mno_enterprise/impac/dashboard.rb +1 -3
- data/app/models/mno_enterprise/impac/kpi.rb +1 -1
- data/app/models/mno_enterprise/impac/widget.rb +1 -1
- data/app/models/mno_enterprise/tenant.rb +4 -2
- data/config/locales/views/auth/registrations/en.yml +1 -1
- data/lib/her_extension/model/associations/belongs_to_association.rb +25 -0
- data/lib/her_extension/model/relation.rb +10 -0
- data/lib/mno_enterprise/core.rb +1 -0
- data/lib/mno_enterprise/testing_support/factories/impac/kpis.rb +0 -1
- data/lib/mno_enterprise/testing_support/factories/tenant.rb +7 -1
- data/lib/mno_enterprise/version.rb +1 -1
- data/spec/lib/her_extension/model/relation_spec.rb +58 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dada02d4020e090a4eefe3fc1edfb48026eb806
|
4
|
+
data.tar.gz: a034f5b750e6952c962dd2a73315b9b6c1f23920
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f7f6a5606f76d090c4a1d7f962703ef121f061fca4eee4ea87f945c2cd32a1396894ffefb7e652e6a4477d4cc1e4c91783f2e33059924eeb04eb1aea20ba9ee
|
7
|
+
data.tar.gz: 601ee2dde7bfd0336c299920703ea6438c2d179fa7c29dfa9f225cc277372aae22bbcb6efb3f26155a4b6120a7011f7bcfb29bb81ea8806cb5129344c8d0e58e
|
@@ -19,9 +19,7 @@ module MnoEnterprise
|
|
19
19
|
# Return all the organizations linked to this dashboard and to which
|
20
20
|
# the user has access
|
21
21
|
def organizations
|
22
|
-
self.organization_ids.
|
23
|
-
MnoEnterprise::Organization.find_by(uid: uid)
|
24
|
-
end
|
22
|
+
MnoEnterprise::Organization.where('uid.in' => self.organization_ids).to_a
|
25
23
|
end
|
26
24
|
|
27
25
|
def sorted_widgets
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module MnoEnterprise
|
2
2
|
class Impac::Kpi < BaseResource
|
3
3
|
|
4
|
-
attributes :
|
4
|
+
attributes :settings, :targets, :extra_params, :endpoint, :source, :element_watched
|
5
5
|
|
6
6
|
belongs_to :dashboard, class_name: 'MnoEnterprise::Impac::Dashboard'
|
7
7
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Backport https://github.com/remiprev/her/pull/343/files
|
2
|
+
# Fix belongs_to when foreign key is nil
|
3
|
+
module Her
|
4
|
+
module Model
|
5
|
+
module Associations
|
6
|
+
class BelongsToAssociation < Association
|
7
|
+
# @private
|
8
|
+
def fetch
|
9
|
+
foreign_key_value = @parent.attributes[@opts[:foreign_key].to_sym]
|
10
|
+
data_key_value = @parent.attributes[@opts[:data_key].to_sym]
|
11
|
+
return @opts[:default].try(:dup) if (@parent.attributes.include?(@name) && @parent.attributes[@name].nil? && @params.empty?) || (foreign_key_value.blank? && data_key_value.blank?)
|
12
|
+
|
13
|
+
return @cached_result unless @params.any? || @cached_result.nil?
|
14
|
+
return @parent.attributes[@name] unless @params.any? || @parent.attributes[@name].blank?
|
15
|
+
|
16
|
+
path_params = @parent.attributes.merge(@params.merge(@klass.primary_key => foreign_key_value))
|
17
|
+
path = build_association_path lambda { @klass.build_request_path(path_params) }
|
18
|
+
@klass.get(path, @params).tap do |result|
|
19
|
+
@cached_result = result if @params.blank?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -35,6 +35,16 @@ module Her
|
|
35
35
|
end
|
36
36
|
alias all where
|
37
37
|
|
38
|
+
# Patch to unwrap filter when creating
|
39
|
+
def first_or_create(attributes = {})
|
40
|
+
fetch.first || create((@params.delete(:filter) || {}).merge(attributes))
|
41
|
+
end
|
42
|
+
|
43
|
+
# Patch to unwrap filter when creating
|
44
|
+
def first_or_initialize(attributes = {})
|
45
|
+
fetch.first || build((@params.delete(:filter) || {}).merge(attributes))
|
46
|
+
end
|
47
|
+
|
38
48
|
# E.g:
|
39
49
|
# Product.order_by('created_at.desc','name.asc')
|
40
50
|
def order_by(*args)
|
data/lib/mno_enterprise/core.rb
CHANGED
@@ -17,6 +17,7 @@ require "her_extension/model/parse"
|
|
17
17
|
require "her_extension/model/associations/association"
|
18
18
|
require "her_extension/model/associations/association_proxy"
|
19
19
|
require "her_extension/model/associations/has_many_association"
|
20
|
+
require "her_extension/model/associations/belongs_to_association"
|
20
21
|
require "her_extension/middleware/mnoe_api_v1_parse_json"
|
21
22
|
require "her_extension/middleware/mnoe_raise_error"
|
22
23
|
require "faraday_middleware"
|
@@ -1,6 +1,8 @@
|
|
1
1
|
FactoryGirl.define do
|
2
2
|
|
3
|
-
|
3
|
+
# Tenant from an old MnoHub (<= v1.0.2)
|
4
|
+
# TODO: Remove once all mnohub are migrated to newer versions
|
5
|
+
factory :old_tenant, class: MnoEnterprise::Tenant do
|
4
6
|
last_portfolio_amount Money.new(65644,'AUD')
|
5
7
|
last_customers_invoicing_amount Money.new(687994,'AUD')
|
6
8
|
last_customers_outstanding_amount Money.new(178986,'AUD')
|
@@ -9,4 +11,8 @@ FactoryGirl.define do
|
|
9
11
|
# Properly build the resource with Her
|
10
12
|
initialize_with { new(attributes).tap { |e| e.clear_attribute_changes! } }
|
11
13
|
end
|
14
|
+
|
15
|
+
factory :tenant, parent: :old_tenant do
|
16
|
+
current_billing_amount Money.new(123456, 'AUD')
|
17
|
+
end
|
12
18
|
end
|
@@ -4,7 +4,8 @@ module MnoEnterprise
|
|
4
4
|
RSpec.describe Her::Model::Relation do
|
5
5
|
pending "add specs for Her::Model::Relation monkey patch: #{__FILE__}"
|
6
6
|
|
7
|
-
|
7
|
+
before(:all) { Object.const_set('DummyClass', Class.new).send(:include, Her::Model) }
|
8
|
+
let(:dummy_class) { DummyClass }
|
8
9
|
|
9
10
|
describe '.where' do
|
10
11
|
it 'adds the filter to params[:filter]' do
|
@@ -17,5 +18,61 @@ module MnoEnterprise
|
|
17
18
|
expect(rel.params[:filter]).to eq('id.in' => nil)
|
18
19
|
end
|
19
20
|
end
|
21
|
+
|
22
|
+
# We mostly test our request expectations
|
23
|
+
describe '.first_or_create' do
|
24
|
+
let(:relation) { Her::Model::Relation.new(dummy_class) }
|
25
|
+
subject { relation.where(foo: 'bar').first_or_create(baz: 'bar') }
|
26
|
+
|
27
|
+
context 'when matching record' do
|
28
|
+
let(:record) { dummy_class.new(foo: 'bar') }
|
29
|
+
before do
|
30
|
+
expect(dummy_class).to receive(:request).with(hash_including(filter: {foo: 'bar'}, _method: :get)).and_return([record])
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the record' do
|
34
|
+
expect(subject).to eq(record)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when no matching record' do
|
39
|
+
before do
|
40
|
+
expect(dummy_class).to receive(:request).with(hash_including(filter: {foo: 'bar'}, _method: :get)).and_return([])
|
41
|
+
expect(dummy_class).to receive(:request).with(hash_including(foo: 'bar', baz: 'bar', _method: :post)).and_return(dummy_class.new)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'creates a new record' do
|
45
|
+
expect(subject).to eq(dummy_class.new(foo: 'bar', baz: 'bar'))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# We mostly test our request expectations
|
51
|
+
describe '.first_or_initialize' do
|
52
|
+
let(:relation) { Her::Model::Relation.new(dummy_class) }
|
53
|
+
subject { relation.where(foo: 'bar').first_or_initialize(baz: 'bar') }
|
54
|
+
|
55
|
+
context 'when matching record' do
|
56
|
+
let(:record) { dummy_class.new(foo: 'bar') }
|
57
|
+
before do
|
58
|
+
expect(dummy_class).to receive(:request).with(hash_including(filter: {foo: 'bar'}, _method: :get)).and_return([record])
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns the record' do
|
62
|
+
expect(subject).to eq(record)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when no matching record' do
|
67
|
+
before do
|
68
|
+
expect(dummy_class).to receive(:request).with(hash_including(filter: {foo: 'bar'}, _method: :get)).and_return([])
|
69
|
+
# No POST stub
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'build a new record' do
|
73
|
+
expect(subject).to eq(dummy_class.new(foo: 'bar', baz: 'bar'))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
20
77
|
end
|
21
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mno-enterprise-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-09-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -481,6 +481,7 @@ files:
|
|
481
481
|
- lib/her_extension/middleware/mnoe_raise_error.rb
|
482
482
|
- lib/her_extension/model/associations/association.rb
|
483
483
|
- lib/her_extension/model/associations/association_proxy.rb
|
484
|
+
- lib/her_extension/model/associations/belongs_to_association.rb
|
484
485
|
- lib/her_extension/model/associations/has_many_association.rb
|
485
486
|
- lib/her_extension/model/attributes.rb
|
486
487
|
- lib/her_extension/model/orm.rb
|
@@ -586,7 +587,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
586
587
|
version: '0'
|
587
588
|
requirements: []
|
588
589
|
rubyforge_project:
|
589
|
-
rubygems_version: 2.
|
590
|
+
rubygems_version: 2.5.1
|
590
591
|
signing_key:
|
591
592
|
specification_version: 4
|
592
593
|
summary: Maestrano Enterprise - Core functionnality
|