pisoni 1.23.2 → 1.24.0

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
  SHA256:
3
- metadata.gz: 9b32b9bf7d4534092ec0a19ef433f354ba6eb2aebf87b315ed53132541ada123
4
- data.tar.gz: b45e5cf8b827909cb87b16336f20ee22186b9e302ce4ff6b948cd822aa556ae2
3
+ metadata.gz: a4dc7a68d6d7ae8b6523c0956c9425a587c53b4cac5a18eb7466e9455c38ef15
4
+ data.tar.gz: e930a4713a961846d6c84207a2435c72f1a957acc6c4ea313c48123a5d953678
5
5
  SHA512:
6
- metadata.gz: 7ed1c92963ec49ba67db747d8070b5020119b5ff61599f499cf1fd628ff0c6d09c4adf286159c3c46dfd119f14ce326e05a0b429cc63b4784efeaee05478a007
7
- data.tar.gz: 8138a68e836ac62f461de46659746b6cc66b2da121c8843132e08570cf141fb551c0ffa738cb5a081e87c5e4e816a969ae3cc3ba3ec95b99100ca8483213f4ae
6
+ metadata.gz: 5aa1351666750cd74d9b55652268155898ec5e3554bd085f8d0590fadc8d1a60d63152f6e31d7f7f48da191f26a503a543a6b6b31a470739f6af1a23d0aad11d
7
+ data.tar.gz: a40c08e47e58ec21db44a12e01dc0b202f0d264a34677ca9029fa23816689acb7426f4fe7d2a24abd6cb08f17c4833ea417a8d46e4833fdd3885b56b29c2d095
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Notable changes to Pisoni will be tracked in this document.
4
4
 
5
+ ## 1.24.0 - 2018-06-29
6
+
7
+ ### Added
8
+
9
+ - Services can now be activated/deactivated based on the `state` attribute.
10
+ ([#7](https://github.com/3scale/pisoni/pull/7))
11
+
5
12
  ## 1.23.2 - 2018-06-04
6
13
 
7
14
  ### Changed
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  [![CircleCI](https://circleci.com/gh/3scale/pisoni.svg?style=shield)](https://circleci.com/gh/3scale/pisoni)
2
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/4b18ae93abefdba17e0b/maintainability)](https://codeclimate.com/github/3scale/pisoni/maintainability)
3
+ [![Gem Version](https://badge.fury.io/rb/pisoni.svg)](https://badge.fury.io/rb/pisoni)
3
4
 
4
5
  # Pisoni
5
6
 
@@ -3,7 +3,7 @@ module ThreeScale
3
3
  class Service < APIClient::Resource
4
4
  attributes :provider_key, :id, :backend_version, :referrer_filters_required,
5
5
  :user_registration_required, :default_user_plan_id,
6
- :default_user_plan_name, :default_service
6
+ :default_user_plan_name, :default_service, :state
7
7
 
8
8
  class << self
9
9
  def load_by_id(service_id)
@@ -66,6 +66,19 @@ module ThreeScale
66
66
  end
67
67
  end
68
68
 
69
+ def initialize(attributes = {})
70
+ @state = :active
71
+ super(attributes)
72
+ end
73
+
74
+ def activate
75
+ self.state = :active
76
+ end
77
+
78
+ def deactivate
79
+ self.state = :suspended
80
+ end
81
+
69
82
  def referrer_filters_required?
70
83
  @referrer_filters_required
71
84
  end
@@ -74,9 +87,20 @@ module ThreeScale
74
87
  @user_registration_required
75
88
  end
76
89
 
90
+ def active?
91
+ state == :active
92
+ end
93
+
77
94
  def save!
78
95
  self.class.save! attributes
79
96
  end
97
+
98
+ private
99
+
100
+ def state=(value)
101
+ # only :active or nil will be considered as :active
102
+ @state = value.nil? || value.to_sym == :active ? :active : :suspended
103
+ end
80
104
  end
81
105
  end
82
106
  end
@@ -1,5 +1,5 @@
1
1
  module ThreeScale
2
2
  module Core
3
- VERSION = '1.23.2'
3
+ VERSION = '1.24.0'
4
4
  end
5
5
  end
data/spec/service_spec.rb CHANGED
@@ -105,6 +105,28 @@ module ThreeScale
105
105
  Service.save!(@service_params)
106
106
  end.must_raise ServiceRequiresDefaultUserPlan
107
107
  end
108
+
109
+ it 'save active service' do
110
+ service = Service.new(@service_params)
111
+ service.wont_be_nil
112
+ service.activate
113
+ service.active?.must_equal true
114
+ service.save!
115
+ loaded_service = Service.load_by_id(@service_params[:id])
116
+ loaded_service.wont_be_nil
117
+ loaded_service.active?.must_equal true
118
+ end
119
+
120
+ it 'save disable service' do
121
+ service = Service.new(@service_params)
122
+ service.wont_be_nil
123
+ service.deactivate
124
+ service.active?.must_equal false
125
+ service.save!
126
+ loaded_service = Service.load_by_id(@service_params[:id])
127
+ loaded_service.wont_be_nil
128
+ loaded_service.active?.must_equal false
129
+ end
108
130
  end
109
131
 
110
132
  describe '.make_default' do
@@ -154,6 +176,51 @@ module ThreeScale
154
176
  end.must_raise InvalidProviderKeys
155
177
  end
156
178
  end
179
+
180
+ describe '.active?' do
181
+ it 'should be active when service is initialized as active' do
182
+ [
183
+ { state: :active },
184
+ { state: 'active' },
185
+ # even when state is not set
186
+ {},
187
+ # even when state is intentionally set as nil
188
+ { state: nil }
189
+ ].each do |svc_attrs|
190
+ Service.new(svc_attrs).active?.must_equal true
191
+ end
192
+ end
193
+
194
+ it 'should be inactive when service is initialized as disabled' do
195
+ [
196
+ { state: :suspended },
197
+ { state: 'suspended' },
198
+ { state: :something },
199
+ { state: :disable },
200
+ { state: :disabled },
201
+ { state: '1' },
202
+ { state: '0' },
203
+ { state: 'true' },
204
+ { state: 'false' }
205
+ ].each do |svc_attrs|
206
+ Service.new(svc_attrs).active?.must_equal false
207
+ end
208
+ end
209
+
210
+ it 'should be active when the service is activated' do
211
+ s = Service.new(state: :disable)
212
+ s.active?.must_equal false
213
+ s.activate
214
+ s.active?.must_equal true
215
+ end
216
+
217
+ it 'should be disabled when the service is deactivated' do
218
+ s = Service.new(state: :active)
219
+ s.active?.must_equal true
220
+ s.deactivate
221
+ s.active?.must_equal false
222
+ end
223
+ end
157
224
  end
158
225
  end
159
226
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pisoni
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.23.2
4
+ version: 1.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alejandro Martinez Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-04 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday