accounts_client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,8 @@
1
1
  # this module assumes base class has an account_name attribute.
2
+ # and thus responds to:
3
+ # - account_name
4
+ # - account_name=
5
+ # - account_name_changed?
2
6
  module Accounts
3
7
  module BelongsToAccount
4
8
 
@@ -34,6 +38,7 @@ module Accounts
34
38
  # @raises 'This is the wrong account!'
35
39
  # @raises 'This is not a account!'
36
40
  def padma_account_setted_correctly
41
+ # refresh_cached_account_if_needed
37
42
  return if self.padma_account.nil?
38
43
  unless padma_account.is_a?(PadmaAccount)
39
44
  raise 'This is not a account!'
@@ -47,6 +52,13 @@ module Accounts
47
52
  end
48
53
  end
49
54
  end
55
+
56
+ def refresh_cached_account_if_needed
57
+ if self.account_name_changed?
58
+ self.account(force_service_call: true)
59
+ end
60
+ end
61
+
50
62
  end
51
63
  end
52
64
 
@@ -1,3 +1,9 @@
1
+ # This module will include BelongsToUser and BelongsToAccount
2
+ # It requires base class to respond to:
3
+ # - username
4
+ # - account_name
5
+ # - account_name=
6
+ # - account_name_changed?
1
7
  module Accounts
2
8
  module IsAUser
3
9
 
@@ -9,6 +15,8 @@ module Accounts
9
15
  base.send(:delegate, :verbose_help?, to: :padma_user)
10
16
  end
11
17
 
18
+ # @param [Boolean] cache
19
+ # @return [PadmaUser]
12
20
  def padma(cache=true)
13
21
  self.user(force_service_call: !cache)
14
22
  end
@@ -39,13 +47,13 @@ module Accounts
39
47
  # Validates that current_account_name
40
48
  # checking that user belongs to such account
41
49
  def has_access_to_current_account
42
- return if self.current_account.nil? || !self.current_account_id_changed?
50
+ return if self.padma.try(:current_account).nil?
43
51
 
44
52
  if self.enabled_accounts.nil?
45
53
  # nil means error in connection
46
54
  self.errors.add(:current_account_id, I18n.t('user.couldnt_connect_to_check_current_account'))
47
55
  else
48
- unless self.current_account.name.in?(self.enabled_accounts.map{|ea|ea.name})
56
+ unless self.padma.current_account_name.in?(self.enabled_accounts.map{|ea|ea.name})
49
57
  self.errors.add(:current_account_id, I18n.t('user.invalid_current_account'))
50
58
  end
51
59
  end
@@ -0,0 +1,16 @@
1
+ shared_examples_for "it belongs to an account" do
2
+ it { should validate_presence_of :account_name }
3
+ it "should return account on #account" do
4
+ PadmaAccount.should_receive(:find).with(object.account_name).and_return(PadmaAccount.new(account_name: object.account_name))
5
+ object.account.should be_a(PadmaAccount)
6
+ end
7
+ end
8
+
9
+ shared_examples_for "it belongs to a user" do
10
+ it { should validate_presence_of :username}
11
+ it "should return user on #user" do
12
+ PadmaUser.stub(:find).with(object.username).and_return(PadmaUser.new(username: object.username))
13
+ object.user.should be_a(PadmaUser)
14
+ end
15
+ it "should use Rails.cache"
16
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accounts_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-03 00:00:00.000000000 Z
12
+ date: 2012-11-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -53,6 +53,7 @@ files:
53
53
  - app/models/padma_user.rb
54
54
  - app/models/padma_account.rb
55
55
  - lib/accounts/belongs_to_account.rb
56
+ - lib/accounts/shared_examples.rb
56
57
  - lib/accounts/belongs_to_user.rb
57
58
  - lib/accounts/is_a_user.rb
58
59
  - lib/accounts/railties.rb