mno-enterprise-core 2.0.5 → 2.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df3c02b0aa5fa9cd97a8edb8aefb06a5cee969c2
4
- data.tar.gz: ced81cbfa2e983dfa542b98ce104170c43f628a2
3
+ metadata.gz: e97f70735ab98bb1b3bff86657960ced3660fec3
4
+ data.tar.gz: 37550a7f9e952087af9528da9cf42b94ee5fdce9
5
5
  SHA512:
6
- metadata.gz: 66791d40f8e3cd76e86b4d0fc072ac4d77b863e19bc31c655907b551529deb80c8b3ad685095f8fe4cf482c02eafef77f52e44a070ab484355ba7ced201672b7
7
- data.tar.gz: 41388bf89759e93a4bedaa2c2605143a28bbb3be5204bc814b10f7eb48c8d0f80a374848ccaaa6304999730bedc0a583fda9332a30852cd27f61d36294e65013
6
+ metadata.gz: e5b872bbc67a77473f0bf98c4dce1cfbb73d5e92b7662305613af70ca0f399575922e99fd464799fef86784e616a1851b2908de0c783d39ae26fbf11a7a7bb89
7
+ data.tar.gz: b7f2a1a8f29ca87ee0dd196c703d32a0596d3e444409573ea3f026bdc8d4f607ec289973017fac519a3ddfa9e604dcaaafdccccc03a201fc775f343789e34b46
@@ -3,31 +3,29 @@ module MnoEnterprise
3
3
 
4
4
  attributes :name, :widgets_order, :organization_ids, :widgets_templates, :currency
5
5
 
6
- has_many :widgets, class_name: 'MnoEnterprise::Impac::Widget', dependent: :destroy
7
- has_many :kpis, class_name: 'MnoEnterprise::Impac::Kpi', dependent: :destroy
8
- belongs_to :owner, polymorphic: true
9
-
10
- #============================================
11
- # Instance methods
12
- #============================================
13
- # Return the full name of this dashboard
14
- # Currently a simple accessor to the dashboard name (used to include the company name)
15
- def full_name
16
- self.name
17
- end
18
-
19
- # Return all the organizations linked to this dashboard and to which
20
- # the user has access
21
- def organizations
22
- self.organization_ids.map do |uid|
23
- MnoEnterprise::Organization.find_by(uid: uid)
24
- end
25
- end
6
+ has_many :widgets, class_name: 'MnoEnterprise::Impac::Widget', dependent: :destroy
7
+ has_many :kpis, class_name: 'MnoEnterprise::Impac::Kpi', dependent: :destroy
8
+ belongs_to :owner, polymorphic: true
26
9
 
27
- def sorted_widgets
28
- order = self.widgets_order.map(&:to_i) | self.widgets.map{|w| w.id }
29
- order.map { |id| self.widgets.to_a.find{ |w| w.id == id} }.compact
30
- end
10
+ #============================================
11
+ # Instance methods
12
+ #============================================
13
+ # Return the full name of this dashboard
14
+ # Currently a simple accessor to the dashboard name (used to include the company name)
15
+ def full_name
16
+ self.name
17
+ end
18
+
19
+ # Return all the organizations linked to this dashboard and to which
20
+ # the user has access
21
+ def organizations
22
+ MnoEnterprise::Organization.where('uid.in' => self.organization_ids).to_a
23
+ end
24
+
25
+ def sorted_widgets
26
+ order = self.widgets_order.map(&:to_i) | self.widgets.map{|w| w.id }
27
+ order.map { |id| self.widgets.to_a.find{ |w| w.id == id} }.compact
28
+ end
31
29
 
32
30
  def to_audit_event
33
31
  name
@@ -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
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module MnoEnterprise
2
- VERSION = '2.0.5'
2
+ VERSION = '2.0.6'
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: 2.0.5
4
+ version: 2.0.6
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-09-09 00:00:00.000000000 Z
12
+ date: 2016-09-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -402,7 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
402
402
  version: '0'
403
403
  requirements: []
404
404
  rubyforge_project:
405
- rubygems_version: 2.5.1
405
+ rubygems_version: 2.4.8
406
406
  signing_key:
407
407
  specification_version: 4
408
408
  summary: Maestrano Enterprise - Core functionnality