mno-enterprise-core 3.0.4 → 3.0.5
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: da4207286ebdd33f06ebc63de2fcf95442d7dd26
|
4
|
+
data.tar.gz: 6bab06e2916773b52895e24033351c8f1280f3bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ca3d815b36466a49bffe953debbec31d86012e6afcd22d73b553e4ecef5e09afe456e218e28d9c560f5c8ceddead4f0e0b8e8661cef8326bbc3a003f36d35c6
|
7
|
+
data.tar.gz: 8aae09a1167b88e89ca90f6b167fdb2ca9eaaf07aee35d51f91bd39ffbe30a84d9eb0ecd48fb21657978d6becb0f01b74357253e1c8be1d40c36b8afa34d2ab4
|
@@ -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.0.
|
4
|
+
version: 3.0.5
|
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
|
@@ -448,6 +448,7 @@ files:
|
|
448
448
|
- lib/her_extension/middleware/mnoe_raise_error.rb
|
449
449
|
- lib/her_extension/model/associations/association.rb
|
450
450
|
- lib/her_extension/model/associations/association_proxy.rb
|
451
|
+
- lib/her_extension/model/associations/belongs_to_association.rb
|
451
452
|
- lib/her_extension/model/associations/has_many_association.rb
|
452
453
|
- lib/her_extension/model/attributes.rb
|
453
454
|
- lib/her_extension/model/orm.rb
|
@@ -539,7 +540,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
539
540
|
version: '0'
|
540
541
|
requirements: []
|
541
542
|
rubyforge_project:
|
542
|
-
rubygems_version: 2.
|
543
|
+
rubygems_version: 2.5.1
|
543
544
|
signing_key:
|
544
545
|
specification_version: 4
|
545
546
|
summary: Maestrano Enterprise - Core functionnality
|