cybercoach 0.3.0 → 0.4.0

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.
@@ -45,11 +45,11 @@ module CyberCoach
45
45
  #
46
46
 
47
47
  attr_accessor :username,
48
- :email,
49
- :password,
50
- :real_name,
51
- :privacy_level,
52
- :date_created
48
+ :email,
49
+ :password,
50
+ :real_name,
51
+ :privacy_level,
52
+ :date_created
53
53
 
54
54
  #
55
55
  # :category: Serialization
@@ -155,5 +155,9 @@ module CyberCoach
155
155
  def invalidate_options
156
156
  @options = @options.merge(authentication)
157
157
  end
158
+
159
+ def initializable_with
160
+ super + [:username, :email, :password, :real_name, :privacy_level]
161
+ end
158
162
  end
159
163
  end
@@ -6,5 +6,5 @@ module CyberCoach
6
6
  #
7
7
  # The current version of the gem.
8
8
  #
9
- VERSION = '0.3.0'
9
+ VERSION = '0.4.0'
10
10
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Entry' do
4
4
  before(:context) do
5
- @proposer = UserHelper.make(6)
6
- @proposed = UserHelper.make(7)
5
+ @proposer = UserHelper.make(8)
6
+ @proposed = UserHelper.make(9)
7
7
  ResourceHelper.safe_delete(@proposer)
8
8
  ResourceHelper.safe_delete(@proposed)
9
9
  @proposer.create
@@ -12,10 +12,10 @@ describe 'Entry' do
12
12
  @partnership.proposer = @proposer
13
13
  @partnership.proposed = @proposed
14
14
  @partnership.privacy_level = CyberCoach::PrivacyLevel::REGISTERED_USER
15
- ResourceHelper.safe_delete(@partnership, UserHelper.options(@proposer))
16
- ResourceHelper.safe_delete(@partnership, UserHelper.options(@proposed))
17
- @partnership.create(UserHelper.options(@proposer))
18
- @partnership.update(UserHelper.options(@proposed))
15
+ ResourceHelper.safe_delete(@partnership, @proposer.authentication)
16
+ ResourceHelper.safe_delete(@partnership, @proposed.authentication)
17
+ @partnership.create(@proposer.authentication)
18
+ @partnership.update(@proposed.authentication)
19
19
  @sport = CyberCoach::Sport.new
20
20
  @sport.name = 'Running'
21
21
  @sport.read
@@ -23,13 +23,13 @@ describe 'Entry' do
23
23
  @subscription.subscriber = @partnership
24
24
  @subscription.sport = @sport
25
25
  @subscription.privacy_level = CyberCoach::PrivacyLevel::REGISTERED_USER
26
- @subscription.create(UserHelper.options(@proposer))
26
+ @subscription.create(@proposer.authentication)
27
27
  end
28
28
 
29
29
  after(:context) do
30
- ResourceHelper.safe_delete(@subscription, UserHelper.options(@proposer))
31
- ResourceHelper.safe_delete(@partnership, UserHelper.options(@proposer))
32
- ResourceHelper.safe_delete(@partnership, UserHelper.options(@proposed))
30
+ ResourceHelper.safe_delete(@subscription, @proposer.authentication)
31
+ ResourceHelper.safe_delete(@partnership, @proposer.authentication)
32
+ ResourceHelper.safe_delete(@partnership, @proposed.authentication)
33
33
  ResourceHelper.safe_delete(@proposer)
34
34
  ResourceHelper.safe_delete(@proposed)
35
35
  end
@@ -43,28 +43,57 @@ describe 'Entry' do
43
43
  @entry.privacy_level = CyberCoach::PrivacyLevel::REGISTERED_USER
44
44
  end
45
45
 
46
+ it 'should instantiate itself with preset attributes' do
47
+ uri = '/pants/'
48
+ id = 1
49
+ subscription = CyberCoach::Subscription.new
50
+ comment = 'those pants are fancy'
51
+ location = 'in your pants'
52
+ duration = 123
53
+ privacy_level = CyberCoach::PrivacyLevel::OWNER
54
+ pants = 'yes'
55
+ @entry = CyberCoach::Entry.new(
56
+ uri: uri,
57
+ id: id,
58
+ subscription: subscription,
59
+ comment: comment,
60
+ location: location,
61
+ duration: duration,
62
+ privacy_level: privacy_level,
63
+ pants: pants
64
+ )
65
+ expect(@entry.uri).to be(uri)
66
+ expect(@entry.id).to be(id)
67
+ expect(@entry.subscription).to be(subscription)
68
+ expect(@entry.comment).to be(comment)
69
+ expect(@entry.location).to be(location)
70
+ expect(@entry.duration).to be(duration)
71
+ expect(@entry.privacy_level).to be(privacy_level)
72
+ expect { @entry.pants }.to raise_error(NoMethodError)
73
+ end
74
+
46
75
  it 'should raise an error if it does not exist' do
47
76
  @entry.id = 1
48
- expect { @entry.read(UserHelper.options(@proposer)) }.to raise_error(CyberCoach::HttpError)
77
+ expect { @entry.read(@proposer.authentication) }.to raise_error(CyberCoach::HttpError)
49
78
  end
50
79
 
51
80
  describe 'crud' do
52
81
  before(:example) do
53
- ResourceHelper.safe_delete(@entry, UserHelper.options(@proposer))
82
+ ResourceHelper.safe_delete(@entry, @proposer.authentication)
54
83
  end
55
84
 
56
85
  after(:example) do
57
- ResourceHelper.safe_delete(@entry, UserHelper.options(@proposer))
86
+ ResourceHelper.safe_delete(@entry, @proposer.authentication)
58
87
  end
59
88
 
60
89
  it 'should create itself' do
61
- @entry.create(UserHelper.options(@proposer))
90
+ @entry.create(@proposer.authentication)
62
91
  expect(@entry.id).not_to be_nil
63
92
  end
64
93
 
65
94
  it 'should read itself' do
66
- @entry.create(UserHelper.options(@proposer))
67
- @entry.read(UserHelper.options(@proposer))
95
+ @entry.create(@proposer.authentication)
96
+ @entry.read(@proposer.authentication)
68
97
  expect(@entry.id).not_to be_nil
69
98
  expect(@entry.uri).not_to be_nil
70
99
  expect(@entry.subscription.uri).to eq(@subscription.uri)
@@ -77,19 +106,65 @@ describe 'Entry' do
77
106
  end
78
107
 
79
108
  it 'should update itself' do
80
- @entry.create(UserHelper.options(@proposer))
109
+ @entry.create(@proposer.authentication)
81
110
  old_privacy_level = @entry.privacy_level
82
111
  new_privacy_level = CyberCoach::PrivacyLevel::EVERYBODY
83
112
  @entry.privacy_level = new_privacy_level
84
- @entry.update(UserHelper.options(@proposer))
113
+ @entry.update(@proposer.authentication)
85
114
  expect(@entry.privacy_level).not_to eq(old_privacy_level)
86
115
  expect(@entry.privacy_level).to eq(new_privacy_level)
87
116
  end
88
117
 
89
118
  it 'should delete itself' do
90
- @entry.create(UserHelper.options(@proposer))
91
- @entry.delete(UserHelper.options(@proposer))
92
- expect { @entry.read(UserHelper.options(@proposer)) }.to raise_error(CyberCoach::HttpError)
119
+ @entry.create(@proposer.authentication)
120
+ @entry.delete(@proposer.authentication)
121
+ expect { @entry.read(@proposer.authentication) }.to raise_error(CyberCoach::HttpError)
122
+ end
123
+ end
124
+
125
+ describe 'invalidation' do
126
+ before(:example) do
127
+ ResourceHelper.safe_delete(@entry, @proposer.authentication)
128
+ end
129
+
130
+ after(:example) do
131
+ ResourceHelper.safe_delete(@entry, @proposer.authentication)
132
+ end
133
+
134
+ xit 'should not invalidate when creating' do
135
+ # TODO crap, this impossible to test...
136
+ id = @entry.id
137
+ @entry.id = 1234
138
+ expect(@entry.id).not_to eq(id)
139
+ expect { @entry.create(@proposer.authentication, false) }.not_to raise_error
140
+ @entry.id = id
141
+ end
142
+
143
+ it 'should not invalidate when reading' do
144
+ @entry.create(@proposer.authentication)
145
+ id = @entry.id
146
+ @entry.id = 1234
147
+ expect(@entry.id).not_to eq(id)
148
+ expect { @entry.read(@proposer.authentication, false) }.not_to raise_error
149
+ @entry.id = id
150
+ end
151
+
152
+ it 'should not invalidate when updating' do
153
+ @entry.create(@proposer.authentication)
154
+ id = @entry.id
155
+ @entry.id = 1234
156
+ expect(@entry.id).not_to eq(id)
157
+ expect { @entry.update(@proposer.authentication, false) }.not_to raise_error
158
+ @entry.id = id
159
+ end
160
+
161
+ it 'should not invalidate when deleting' do
162
+ @entry.create(@proposer.authentication)
163
+ id = @entry.id
164
+ @entry.id = 1234
165
+ expect(@entry.id).not_to eq(id)
166
+ expect { @entry.delete(@proposer.authentication, false) }.not_to raise_error
167
+ @entry.id = id
93
168
  end
94
169
  end
95
- end
170
+ end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Partnership' do
4
4
  before(:context) do
5
- @proposer = UserHelper.make(6)
6
- @proposed = UserHelper.make(7)
5
+ @proposer = UserHelper.make(8)
6
+ @proposed = UserHelper.make(9)
7
7
  ResourceHelper.safe_delete(@proposer)
8
8
  ResourceHelper.safe_delete(@proposed)
9
9
  @proposer.create
@@ -22,8 +22,31 @@ describe 'Partnership' do
22
22
  @partnership.privacy_level = CyberCoach::PrivacyLevel::REGISTERED_USER
23
23
  end
24
24
 
25
+ it 'should instantiate itself with preset attributes' do
26
+ uri = '/pants/'
27
+ id = 1
28
+ proposer = CyberCoach::User.new
29
+ proposed = CyberCoach::User.new
30
+ privacy_level = CyberCoach::PrivacyLevel::OWNER
31
+ pants = 'yes'
32
+ @partnership = CyberCoach::Partnership.new(
33
+ uri: uri,
34
+ id: id,
35
+ proposer: proposer,
36
+ proposed: proposed,
37
+ privacy_level: privacy_level,
38
+ pants: pants
39
+ )
40
+ expect(@partnership.uri).to be(uri)
41
+ expect(@partnership.id).to be(id)
42
+ expect(@partnership.proposer).to be(proposer)
43
+ expect(@partnership.proposed).to be(proposed)
44
+ expect(@partnership.privacy_level).to be(privacy_level)
45
+ expect { @partnership.pants }.to raise_error(NoMethodError)
46
+ end
47
+
25
48
  it 'should raise an error if it does not exist' do
26
- expect { @partnership.read(UserHelper.options(@proposer)) }.to raise_error(CyberCoach::HttpError)
49
+ expect { @partnership.read(@proposer.authentication) }.to raise_error(CyberCoach::HttpError)
27
50
  end
28
51
 
29
52
  it 'should read all' do
@@ -35,21 +58,21 @@ describe 'Partnership' do
35
58
 
36
59
  describe 'crud' do
37
60
  before(:example) do
38
- ResourceHelper.safe_delete(@partnership, UserHelper.options(@proposer))
61
+ ResourceHelper.safe_delete(@partnership, @proposer.authentication)
39
62
  end
40
63
 
41
64
  after(:example) do
42
- ResourceHelper.safe_delete(@partnership, UserHelper.options(@proposer))
65
+ ResourceHelper.safe_delete(@partnership, @proposer.authentication)
43
66
  end
44
67
 
45
68
  it 'should create itself' do
46
- @partnership.create(UserHelper.options(@proposer))
69
+ @partnership.create(@proposer.authentication)
47
70
  expect(@partnership.id).not_to be_nil
48
71
  end
49
72
 
50
73
  it 'should read itself' do
51
- @partnership.create(UserHelper.options(@proposer))
52
- @partnership.read(UserHelper.options(@proposer))
74
+ @partnership.create(@proposer.authentication)
75
+ @partnership.read(@proposer.authentication)
53
76
  expect(@partnership.id).not_to be_nil
54
77
  expect(@partnership.uri).not_to be_nil
55
78
  expect(@partnership.proposer.uri).to eq(@proposer.uri)
@@ -61,19 +84,64 @@ describe 'Partnership' do
61
84
  end
62
85
 
63
86
  it 'should update itself' do
64
- @partnership.create(UserHelper.options(@proposer))
87
+ @partnership.create(@proposer.authentication)
65
88
  old_privacy_level = @partnership.privacy_level
66
89
  new_privacy_level = CyberCoach::PrivacyLevel::EVERYBODY
67
90
  @partnership.privacy_level = new_privacy_level
68
- @partnership.update(UserHelper.options(@proposer))
91
+ @partnership.update(@proposer.authentication)
69
92
  expect(@partnership.privacy_level).not_to eq(old_privacy_level)
70
93
  expect(@partnership.privacy_level).to eq(new_privacy_level)
71
94
  end
72
95
 
73
96
  it 'should delete itself' do
74
- @partnership.create(UserHelper.options(@proposer))
75
- @partnership.delete(UserHelper.options(@proposer))
76
- expect { @partnership.read(UserHelper.options(@proposer)) }.to raise_error(CyberCoach::HttpError)
97
+ @partnership.create(@proposer.authentication)
98
+ @partnership.delete(@proposer.authentication)
99
+ expect { @partnership.read(@proposer.authentication) }.to raise_error(CyberCoach::HttpError)
100
+ end
101
+ end
102
+
103
+ describe 'invalidation' do
104
+ before(:example) do
105
+ ResourceHelper.safe_delete(@partnership, @proposer.authentication)
106
+ end
107
+
108
+ after(:example) do
109
+ ResourceHelper.safe_delete(@partnership, @proposer.authentication)
110
+ end
111
+
112
+ it 'should not invalidate when creating' do
113
+ proposer = @partnership.proposer
114
+ @partnership.proposer = CyberCoach::User.new
115
+ expect(@partnership.proposer).not_to eq(proposer)
116
+ expect { @partnership.create(@proposer.authentication, false) }.not_to raise_error
117
+ @partnership.proposer = proposer
118
+ end
119
+
120
+ it 'should not invalidate when reading' do
121
+ @partnership.create(@proposer.authentication)
122
+ proposer = @partnership.proposer
123
+ @partnership.proposer = CyberCoach::User.new
124
+ expect(@partnership.proposer).not_to eq(proposer)
125
+ expect { @partnership.read(@proposer.authentication, false) }.not_to raise_error
126
+ @partnership.proposer = proposer
127
+ end
128
+
129
+ it 'should not invalidate when updating' do
130
+ @partnership.create(@proposer.authentication)
131
+ proposer = @partnership.proposer
132
+ @partnership.proposer = CyberCoach::User.new
133
+ expect(@partnership.proposer).not_to eq(proposer)
134
+ expect { @partnership.update(@proposer.authentication, false) }.not_to raise_error
135
+ @partnership.proposer = proposer
136
+ end
137
+
138
+ it 'should not invalidate when deleting' do
139
+ @partnership.create(@proposer.authentication)
140
+ proposer = @partnership.proposer
141
+ @partnership.proposer = CyberCoach::User.new
142
+ expect(@partnership.proposer).not_to eq(proposer)
143
+ expect { @partnership.delete(@proposer.authentication, false) }.not_to raise_error
144
+ @partnership.proposer = proposer
77
145
  end
78
146
  end
79
- end
147
+ end
@@ -12,4 +12,4 @@ describe 'PrivacyLevel' do
12
12
  it 'should have an EVERYBODY level' do
13
13
  expect(CyberCoach::PrivacyLevel::EVERYBODY).to eq(2)
14
14
  end
15
- end
15
+ end
@@ -20,6 +20,33 @@ describe 'ResourcePage' do
20
20
  end
21
21
  end
22
22
 
23
+ it 'should need :type to instantiate' do
24
+ expect { CyberCoach::ResourcePage.new }.to raise_error(ArgumentError)
25
+ end
26
+
27
+ it 'should instantiate itself with preset attributes' do
28
+ uri = '/pants/'
29
+ type = CyberCoach::User
30
+ start = 1
31
+ end_ = 6
32
+ size = 5
33
+ pants = 'yes'
34
+ @page = CyberCoach::ResourcePage.new(
35
+ uri: uri,
36
+ type: type,
37
+ start: start,
38
+ end: end_,
39
+ size: size,
40
+ pants: pants
41
+ )
42
+ expect(@page.uri).to be(uri)
43
+ expect(@page.type).to be(type)
44
+ expect(@page.start).to be(start)
45
+ expect(@page.end).to be(end_)
46
+ expect(@page.size).to be(size)
47
+ expect { @page.pants }.to raise_error(NoMethodError)
48
+ end
49
+
23
50
  it 'should read itself' do
24
51
  @page.start = 1
25
52
  @page.size = 2
@@ -29,8 +56,20 @@ describe 'ResourcePage' do
29
56
  expect(@page.end).to eq(3)
30
57
  end
31
58
 
59
+ it 'should not invalidate when reading' do
60
+ start = @page.start
61
+ size = @page.size
62
+ @page.start = 5
63
+ @page.size = 6
64
+ expect(@page.size).not_to eq(size)
65
+ expect(@page.start).not_to eq(start)
66
+ @page.read({}, false)
67
+ expect(@page.size).to eq(size)
68
+ expect(@page.start).to eq(start)
69
+ end
70
+
32
71
  it 'should be able to navigate between pages' do
33
- expect{@page.previous}.to raise_error(CyberCoach::ResourcePage::NoPreviousPageError)
72
+ expect { @page.previous }.to raise_error(CyberCoach::ResourcePage::NoPreviousPageError)
34
73
  next_page = @page.next
35
74
  expect(next_page.resources).not_to be_empty
36
75
  expect(next_page.start).to eq(@page.end)
@@ -41,4 +80,4 @@ describe 'ResourcePage' do
41
80
  next_previous_page = next_page.previous
42
81
  expect(next_previous_page.resources[0].uri).to eq(@page.resources[0].uri)
43
82
  end
44
- end
83
+ end
@@ -7,4 +7,4 @@ describe 'Settings' do
7
7
  it 'should have a server URI' do
8
8
  expect(CyberCoach::Settings::SERVER_URI).not_to be_nil
9
9
  end
10
- end
10
+ end
@@ -5,6 +5,26 @@ describe 'Sport' do
5
5
  @sport = CyberCoach::Sport.new
6
6
  end
7
7
 
8
+ it 'should instantiate itself with preset attributes' do
9
+ uri = '/pants/'
10
+ id = 1
11
+ name = 'pants'
12
+ description = 'very fancy'
13
+ pants = 'yes'
14
+ @sport = CyberCoach::Sport.new(
15
+ uri: uri,
16
+ id: id,
17
+ name: name,
18
+ description: description,
19
+ pants: pants
20
+ )
21
+ expect(@sport.uri).to be(uri)
22
+ expect(@sport.id).to be(id)
23
+ expect(@sport.name).to be(name)
24
+ expect(@sport.description).to be(description)
25
+ expect { @sport.pants }.to raise_error(NoMethodError)
26
+ end
27
+
8
28
  it 'should read itself' do
9
29
  @sport.name = 'Running'
10
30
  @sport.read
@@ -15,15 +35,25 @@ describe 'Sport' do
15
35
  expect(@sport.subscriptions).not_to be_empty
16
36
  end
17
37
 
38
+ it 'should not invalidate when reading' do
39
+ @sport.name = 'Running'
40
+ @sport.read
41
+ name = @sport.name
42
+ @sport.name = 'notTheName'
43
+ expect(@sport.name).not_to eq(name)
44
+ expect { @sport.read({}, false) }.not_to raise_error
45
+ @sport.name = name
46
+ end
47
+
18
48
  it 'should raise an error if it does not exist' do
19
49
  @sport.name = 'Pants'
20
- expect{@sport.read}.to raise_error(CyberCoach::HttpError)
50
+ expect { @sport.read }.to raise_error(CyberCoach::HttpError)
21
51
  end
22
52
 
23
53
  it 'should read all' do
24
54
  sports = CyberCoach::Sport.read_all
25
55
  expect(sports.resources.size).to eq(4)
26
- expect{sports.next}.to raise_error(CyberCoach::ResourcePage::NoNextPageError)
27
- expect{sports.previous}.to raise_error(CyberCoach::ResourcePage::NoPreviousPageError)
56
+ expect { sports.next }.to raise_error(CyberCoach::ResourcePage::NoNextPageError)
57
+ expect { sports.previous }.to raise_error(CyberCoach::ResourcePage::NoPreviousPageError)
28
58
  end
29
- end
59
+ end