mno-enterprise-core 3.1.1 → 3.1.2

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: 65ad5fd0badd5b1b262d37cec7072456038fb961
4
- data.tar.gz: 5c4a566cd957070e836af6a3d7ada961f80242f2
3
+ metadata.gz: 7dada02d4020e090a4eefe3fc1edfb48026eb806
4
+ data.tar.gz: a034f5b750e6952c962dd2a73315b9b6c1f23920
5
5
  SHA512:
6
- metadata.gz: 17d9bd4a3783ad23a7882ebac470cda39b8879df49050a17cee7a612afd1acf60b47f3d089d4335ada1900fecfed572ff4747139e7a19be6c650a2c562ff47e6
7
- data.tar.gz: f42a459f8bd6e7f5b22d330e3d7fd2fbfa4de1b58ac5e05d716371ec9281dfa095fbbc3a2c60527d3ea5b9137f784924ced36b44e73d86125e6aa911ae3e4293
6
+ metadata.gz: 1f7f6a5606f76d090c4a1d7f962703ef121f061fca4eee4ea87f945c2cd32a1396894ffefb7e652e6a4477d4cc1e4c91783f2e33059924eeb04eb1aea20ba9ee
7
+ data.tar.gz: 601ee2dde7bfd0336c299920703ea6438c2d179fa7c29dfa9f225cc277372aae22bbcb6efb3f26155a4b6120a7011f7bcfb29bb81ea8806cb5129344c8d0e58e
@@ -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.1.1'
2
+ VERSION = '3.1.2'
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.1.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-08-30 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
@@ -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.4.8
590
+ rubygems_version: 2.5.1
590
591
  signing_key:
591
592
  specification_version: 4
592
593
  summary: Maestrano Enterprise - Core functionnality