mno-enterprise-core 3.0.4 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 813c8e1d92349154521dc8890567c5d781cfa6c6
4
- data.tar.gz: 193b99609bab56ce9e15352ca4b4bd4545785683
3
+ metadata.gz: da4207286ebdd33f06ebc63de2fcf95442d7dd26
4
+ data.tar.gz: 6bab06e2916773b52895e24033351c8f1280f3bb
5
5
  SHA512:
6
- metadata.gz: 506c85a6be60f669dd1e757f9fc867f8bdd19824b1140434ffb2221ecbe89ff3744c2e37bb2691551d3451d71d1678e1c0a149c07a2530af7e801f2c872f53b8
7
- data.tar.gz: a5e71645e53acc694ebc7fde9aa497101c449a5e35704b693c1c61c6147db6c586008652183ae574792107da2d5806431b3252ef655408a9eb9248ddaaa4d6a2
6
+ metadata.gz: 2ca3d815b36466a49bffe953debbec31d86012e6afcd22d73b553e4ecef5e09afe456e218e28d9c560f5c8ceddead4f0e0b8e8661cef8326bbc3a003f36d35c6
7
+ data.tar.gz: 8aae09a1167b88e89ca90f6b167fdb2ca9eaaf07aee35d51f91bd39ffbe30a84d9eb0ecd48fb21657978d6becb0f01b74357253e1c8be1d40c36b8afa34d2ab4
@@ -143,7 +143,8 @@ module MnoEnterprise
143
143
  if perform_validations(options)
144
144
  ret = super()
145
145
  process_response_errors
146
- raise_record_invalid
146
+ raise_record_invalid if self.errors.any?
147
+ ret
147
148
  else
148
149
  false
149
150
  end
@@ -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.map do |uid|
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 :name, :settings, :targets, :extra_params, :endpoint, :source, :element_watched
4
+ attributes :settings, :targets, :extra_params, :endpoint, :source, :element_watched
5
5
 
6
6
  belongs_to :dashboard, class_name: 'MnoEnterprise::Impac::Dashboard'
7
7
 
@@ -1,7 +1,7 @@
1
1
  module MnoEnterprise
2
2
  class Impac::Widget < BaseResource
3
3
 
4
- attributes :name, :width, :widget_category, :settings
4
+ attributes :name, :width, :widget_category, :settings
5
5
 
6
6
  belongs_to :dashboard, class_name: 'MnoEnterprise::Impac::Dashboard'
7
7
 
@@ -1,5 +1,7 @@
1
1
  module MnoEnterprise
2
2
  class Tenant < BaseResource
3
-
3
+ def self.show
4
+ self.get('tenant')
5
+ end
4
6
  end
5
- end
7
+ end
@@ -6,4 +6,4 @@ en:
6
6
  title: Sign Up
7
7
  create: Create my account!
8
8
  user_accept: I accept
9
- tos: the Terms of Use
9
+ tos: the Terms of Use
@@ -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)
@@ -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"
@@ -4,7 +4,6 @@ FactoryGirl.define do
4
4
  factory :impac_kpi, class: MnoEnterprise::Impac::Kpi do
5
5
 
6
6
  sequence(:id) { |n| n }
7
- sequence(:name) { |n| "Random Kpi #{n}" }
8
7
  dashboard { build(:impac_dashboard).attributes }
9
8
  endpoint "an/endpoint"
10
9
  element_watched "a_watchable"
@@ -1,6 +1,8 @@
1
1
  FactoryGirl.define do
2
2
 
3
- factory :tenant, class: MnoEnterprise::Tenant do
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
@@ -1,3 +1,3 @@
1
1
  module MnoEnterprise
2
- VERSION = '3.0.4'
2
+ VERSION = '3.0.5'
3
3
  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
- let(:dummy_class) { Class.new { include Her::Model } }
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
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-08-29 00:00:00.000000000 Z
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.4.8
543
+ rubygems_version: 2.5.1
543
544
  signing_key:
544
545
  specification_version: 4
545
546
  summary: Maestrano Enterprise - Core functionnality