entangled 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -6
- data/bower.json +1 -1
- data/entangled.js +1 -1
- data/lib/entangled/version.rb +1 -1
- data/spec/dummy/app/controllers/lists_controller.rb +7 -0
- data/spec/dummy/app/models/list.rb +2 -0
- data/spec/dummy/db/migrate/20150316034305_drop_messages.rb +13 -0
- data/spec/dummy/db/schema.rb +1 -7
- data/spec/dummy/public/app/app.js +1 -9
- data/spec/dummy/public/app/entangled/entangled.js +2 -0
- data/spec/dummy/public/app/services/list.js +3 -3
- data/spec/dummy/public/index.html +0 -3
- data/spec/dummy/public/test/services/entangled_test.js +263 -0
- data/spec/models/list_spec.rb +107 -1
- metadata +6 -22
- data/spec/dummy/app/controllers/messages_controller.rb +0 -41
- data/spec/dummy/public/app/controllers/message.js +0 -15
- data/spec/dummy/public/app/controllers/messages.js +0 -23
- data/spec/dummy/public/app/services/message.js +0 -7
- data/spec/dummy/public/test/controllers/lists_test.js +0 -87
- data/spec/dummy/public/test/controllers/messages_test.js +0 -249
- data/spec/dummy/public/views/messages/index.html +0 -13
- data/spec/dummy/public/views/messages/show.html +0 -8
- data/spec/models/message_spec.rb +0 -135
- data/spec/routing/messages_routing_spec.rb +0 -53
data/spec/models/list_spec.rb
CHANGED
@@ -16,7 +16,7 @@ RSpec.describe List, type: :model do
|
|
16
16
|
describe 'Methods' do
|
17
17
|
let(:list) { List.create(name: 'foo') }
|
18
18
|
|
19
|
-
describe '#
|
19
|
+
describe '#member_channel' do
|
20
20
|
it 'has the right channel' do
|
21
21
|
expect(list.member_channel).to eq "/lists/#{list.to_param}"
|
22
22
|
end
|
@@ -28,4 +28,110 @@ RSpec.describe List, type: :model do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
describe '#entangle' do
|
33
|
+
let(:stub_redis) do
|
34
|
+
mock("redis").tap do |redis|
|
35
|
+
redis.stubs(:publish)
|
36
|
+
Redis.stubs(:new).returns(redis)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'creation' do
|
41
|
+
let(:list) { List.create(name: 'foo') }
|
42
|
+
|
43
|
+
it 'broadcasts the creation to the collection channel' do
|
44
|
+
redis = stub_redis
|
45
|
+
|
46
|
+
expect(redis).to have_received(:publish).with(
|
47
|
+
list.collection_channel, {
|
48
|
+
action: :create,
|
49
|
+
resource: list
|
50
|
+
}.to_json
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'broadcasts the creation to the member channel' do
|
55
|
+
redis = stub_redis
|
56
|
+
|
57
|
+
expect(redis).to have_received(:publish).with(
|
58
|
+
list.member_channel, {
|
59
|
+
action: :create,
|
60
|
+
resource: list
|
61
|
+
}.to_json
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'update' do
|
67
|
+
let!(:list) { List.create(name: 'foo') }
|
68
|
+
|
69
|
+
it 'broadcasts the update to the collection channel' do
|
70
|
+
redis = stub_redis
|
71
|
+
|
72
|
+
list.update(name: 'bar')
|
73
|
+
|
74
|
+
expect(redis).to have_received(:publish).with(
|
75
|
+
list.collection_channel, {
|
76
|
+
action: :update,
|
77
|
+
resource: list
|
78
|
+
}.to_json
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'broadcasts the update to the member channel' do
|
83
|
+
redis = stub_redis
|
84
|
+
|
85
|
+
list.update(name: 'bar')
|
86
|
+
|
87
|
+
expect(redis).to have_received(:publish).with(
|
88
|
+
list.member_channel, {
|
89
|
+
action: :update,
|
90
|
+
resource: list
|
91
|
+
}.to_json
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'destruction' do
|
97
|
+
let!(:list) { List.create(name: 'foo') }
|
98
|
+
|
99
|
+
it 'broadcasts the destruction to the collection channel' do
|
100
|
+
redis = stub_redis
|
101
|
+
|
102
|
+
list.destroy
|
103
|
+
|
104
|
+
expect(redis).to have_received(:publish).with(
|
105
|
+
list.collection_channel, {
|
106
|
+
action: :destroy,
|
107
|
+
resource: list
|
108
|
+
}.to_json
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'broadcasts the destruction to the member channel' do
|
113
|
+
redis = stub_redis
|
114
|
+
|
115
|
+
list.destroy
|
116
|
+
|
117
|
+
expect(redis).to have_received(:publish).with(
|
118
|
+
list.member_channel, {
|
119
|
+
action: :destroy,
|
120
|
+
resource: list
|
121
|
+
}.to_json
|
122
|
+
)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe '#as_json' do
|
128
|
+
it 'includes errors' do
|
129
|
+
list = List.create
|
130
|
+
expect(list.as_json["errors"][:name]).to include "can't be blank"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'Validations' do
|
135
|
+
it { is_expected.to validate_presence_of :name }
|
136
|
+
end
|
31
137
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entangled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dennis Charles Hackethal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -192,7 +192,6 @@ files:
|
|
192
192
|
- spec/dummy/app/controllers/concerns/.keep
|
193
193
|
- spec/dummy/app/controllers/items_controller.rb
|
194
194
|
- spec/dummy/app/controllers/lists_controller.rb
|
195
|
-
- spec/dummy/app/controllers/messages_controller.rb
|
196
195
|
- spec/dummy/app/models/.keep
|
197
196
|
- spec/dummy/app/models/bar.rb
|
198
197
|
- spec/dummy/app/models/barfoo.rb
|
@@ -232,34 +231,27 @@ files:
|
|
232
231
|
- spec/dummy/db/migrate/20150223004852_create_barfoos.rb
|
233
232
|
- spec/dummy/db/migrate/20150314054548_create_lists.rb
|
234
233
|
- spec/dummy/db/migrate/20150314055847_create_items.rb
|
234
|
+
- spec/dummy/db/migrate/20150316034305_drop_messages.rb
|
235
235
|
- spec/dummy/db/schema.rb
|
236
236
|
- spec/dummy/log/.keep
|
237
237
|
- spec/dummy/public/Gruntfile.js
|
238
238
|
- spec/dummy/public/app/app.js
|
239
239
|
- spec/dummy/public/app/controllers/list.js
|
240
240
|
- spec/dummy/public/app/controllers/lists.js
|
241
|
-
- spec/dummy/public/app/controllers/message.js
|
242
|
-
- spec/dummy/public/app/controllers/messages.js
|
243
241
|
- spec/dummy/public/app/entangled/entangled.js
|
244
242
|
- spec/dummy/public/app/services/list.js
|
245
|
-
- spec/dummy/public/app/services/message.js
|
246
243
|
- spec/dummy/public/bower.json
|
247
244
|
- spec/dummy/public/favicon.ico
|
248
245
|
- spec/dummy/public/index.html
|
249
246
|
- spec/dummy/public/package.json
|
250
|
-
- spec/dummy/public/test/
|
251
|
-
- spec/dummy/public/test/controllers/messages_test.js
|
247
|
+
- spec/dummy/public/test/services/entangled_test.js
|
252
248
|
- spec/dummy/public/views/lists/index.html
|
253
249
|
- spec/dummy/public/views/lists/show.html
|
254
|
-
- spec/dummy/public/views/messages/index.html
|
255
|
-
- spec/dummy/public/views/messages/show.html
|
256
250
|
- spec/helpers/redis_spec.rb
|
257
251
|
- spec/models/inclusion_exclusion_spec.rb
|
258
252
|
- spec/models/item_spec.rb
|
259
253
|
- spec/models/list_spec.rb
|
260
|
-
- spec/models/message_spec.rb
|
261
254
|
- spec/routing/inclusion_exclusion_routing_spec.rb
|
262
|
-
- spec/routing/messages_routing_spec.rb
|
263
255
|
- spec/routing/nested_routing_spec.rb
|
264
256
|
- spec/spec_helper.rb
|
265
257
|
homepage: https://github.com/dchacke/entangled
|
@@ -293,7 +285,6 @@ test_files:
|
|
293
285
|
- spec/dummy/app/controllers/concerns/.keep
|
294
286
|
- spec/dummy/app/controllers/items_controller.rb
|
295
287
|
- spec/dummy/app/controllers/lists_controller.rb
|
296
|
-
- spec/dummy/app/controllers/messages_controller.rb
|
297
288
|
- spec/dummy/app/models/.keep
|
298
289
|
- spec/dummy/app/models/bar.rb
|
299
290
|
- spec/dummy/app/models/barfoo.rb
|
@@ -333,33 +324,26 @@ test_files:
|
|
333
324
|
- spec/dummy/db/migrate/20150223004852_create_barfoos.rb
|
334
325
|
- spec/dummy/db/migrate/20150314054548_create_lists.rb
|
335
326
|
- spec/dummy/db/migrate/20150314055847_create_items.rb
|
327
|
+
- spec/dummy/db/migrate/20150316034305_drop_messages.rb
|
336
328
|
- spec/dummy/db/schema.rb
|
337
329
|
- spec/dummy/log/.keep
|
338
330
|
- spec/dummy/public/Gruntfile.js
|
339
331
|
- spec/dummy/public/app/app.js
|
340
332
|
- spec/dummy/public/app/controllers/list.js
|
341
333
|
- spec/dummy/public/app/controllers/lists.js
|
342
|
-
- spec/dummy/public/app/controllers/message.js
|
343
|
-
- spec/dummy/public/app/controllers/messages.js
|
344
334
|
- spec/dummy/public/app/entangled/entangled.js
|
345
335
|
- spec/dummy/public/app/services/list.js
|
346
|
-
- spec/dummy/public/app/services/message.js
|
347
336
|
- spec/dummy/public/bower.json
|
348
337
|
- spec/dummy/public/favicon.ico
|
349
338
|
- spec/dummy/public/index.html
|
350
339
|
- spec/dummy/public/package.json
|
351
|
-
- spec/dummy/public/test/
|
352
|
-
- spec/dummy/public/test/controllers/messages_test.js
|
340
|
+
- spec/dummy/public/test/services/entangled_test.js
|
353
341
|
- spec/dummy/public/views/lists/index.html
|
354
342
|
- spec/dummy/public/views/lists/show.html
|
355
|
-
- spec/dummy/public/views/messages/index.html
|
356
|
-
- spec/dummy/public/views/messages/show.html
|
357
343
|
- spec/helpers/redis_spec.rb
|
358
344
|
- spec/models/inclusion_exclusion_spec.rb
|
359
345
|
- spec/models/item_spec.rb
|
360
346
|
- spec/models/list_spec.rb
|
361
|
-
- spec/models/message_spec.rb
|
362
347
|
- spec/routing/inclusion_exclusion_routing_spec.rb
|
363
|
-
- spec/routing/messages_routing_spec.rb
|
364
348
|
- spec/routing/nested_routing_spec.rb
|
365
349
|
- spec/spec_helper.rb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# This controller serves as fully restful example
|
2
|
-
# controller with all five actions
|
3
|
-
class MessagesController < ApplicationController
|
4
|
-
include Entangled::Controller
|
5
|
-
|
6
|
-
def index
|
7
|
-
broadcast do
|
8
|
-
@messages = Message.all
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def show
|
13
|
-
broadcast do
|
14
|
-
@message = Message.find(params[:id])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
broadcast do
|
20
|
-
@message = Message.create(message_params)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def update
|
25
|
-
broadcast do
|
26
|
-
@message = Message.find(params[:id])
|
27
|
-
@message.update(message_params)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def destroy
|
32
|
-
broadcast do
|
33
|
-
@message = Message.find(params[:id]).destroy
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
def message_params
|
39
|
-
params.require(:message).permit(:body)
|
40
|
-
end
|
41
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
angular.module('entangledTest')
|
4
|
-
|
5
|
-
.controller('MessageCtrl', function($scope, $routeParams, Message) {
|
6
|
-
$scope.update = function() {
|
7
|
-
$scope.message.$save();
|
8
|
-
};
|
9
|
-
|
10
|
-
Message.find($routeParams.id, function(message) {
|
11
|
-
$scope.$apply(function() {
|
12
|
-
$scope.message = message;
|
13
|
-
});
|
14
|
-
});
|
15
|
-
});
|
@@ -1,23 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
angular.module('entangledTest')
|
4
|
-
|
5
|
-
.controller('MessagesCtrl', function($scope, Message) {
|
6
|
-
$scope.message = Message.new();
|
7
|
-
|
8
|
-
$scope.create = function() {
|
9
|
-
$scope.message.$save(function() {
|
10
|
-
$scope.message = Message.new();
|
11
|
-
});
|
12
|
-
};
|
13
|
-
|
14
|
-
$scope.destroy = function(message) {
|
15
|
-
message.$destroy();
|
16
|
-
};
|
17
|
-
|
18
|
-
Message.all(function(messages) {
|
19
|
-
$scope.$apply(function() {
|
20
|
-
$scope.messages = messages;
|
21
|
-
});
|
22
|
-
});
|
23
|
-
});
|
@@ -1,87 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
describe('ListsCtrl', function() {
|
4
|
-
beforeEach(module('entangledTest'));
|
5
|
-
|
6
|
-
var ListsCtrl,
|
7
|
-
scope,
|
8
|
-
List;
|
9
|
-
|
10
|
-
beforeEach(inject(function ($controller, $rootScope, $injector) {
|
11
|
-
scope = $rootScope.$new();
|
12
|
-
ListsCtrl = $controller('ListsCtrl', {
|
13
|
-
$scope: scope
|
14
|
-
}),
|
15
|
-
List = $injector.get('List');
|
16
|
-
}));
|
17
|
-
|
18
|
-
it('fetches all lists', function(done) {
|
19
|
-
List.all(function(lists) {
|
20
|
-
expect(lists).toEqual(jasmine.any(Array));
|
21
|
-
done();
|
22
|
-
});
|
23
|
-
});
|
24
|
-
|
25
|
-
it("fetches a list's items after creating it", function(done) {
|
26
|
-
List.create({ name: 'foo' }, function(list) {
|
27
|
-
// Assert that list has been persisted
|
28
|
-
expect(list.$persisted()).toBeTruthy();
|
29
|
-
|
30
|
-
// Fetch list's items
|
31
|
-
list.items().all(function(items) {
|
32
|
-
expect(items).toEqual(jasmine.any(Array));
|
33
|
-
done();
|
34
|
-
});
|
35
|
-
});
|
36
|
-
});
|
37
|
-
|
38
|
-
it("fetches a list's items after fetching it", function(done) {
|
39
|
-
List.create({ name: 'foo' }, function(list) {
|
40
|
-
// Fetch list
|
41
|
-
List.find(list.id, function(list) {
|
42
|
-
// Assert that list is persisted
|
43
|
-
expect(list.$persisted).toBeTruthy();
|
44
|
-
|
45
|
-
// Fetch list's items
|
46
|
-
list.items().all(function(items) {
|
47
|
-
expect(items).toEqual(jasmine.any(Array));
|
48
|
-
done();
|
49
|
-
});
|
50
|
-
});
|
51
|
-
});
|
52
|
-
});
|
53
|
-
|
54
|
-
it("fetches a list's items when fetching all lists", function(done) {
|
55
|
-
List.all(function(lists) {
|
56
|
-
var list = lists[0];
|
57
|
-
|
58
|
-
// Assert that list is persisted
|
59
|
-
expect(list.$persisted()).toBeTruthy();
|
60
|
-
|
61
|
-
// Fetch list's items
|
62
|
-
list.items().all(function(items) {
|
63
|
-
expect(items).toEqual(jasmine.any(Array));
|
64
|
-
done();
|
65
|
-
});
|
66
|
-
});
|
67
|
-
});
|
68
|
-
|
69
|
-
it("creates and finds a list's item", function(done) {
|
70
|
-
List.create({ name: 'foo' }, function(list) {
|
71
|
-
// Create item
|
72
|
-
list.items().create({ name: 'foo' }, function(item) {
|
73
|
-
// Assert that item has been persisted
|
74
|
-
expect(item.$persisted()).toBeTruthy();
|
75
|
-
|
76
|
-
// Assert that item's list_id is equal to the list's id
|
77
|
-
expect(item.list_id).toBe(list.id);
|
78
|
-
|
79
|
-
// Assert that it can find the item
|
80
|
-
list.items().find(item.id, function(item) {
|
81
|
-
expect(item.$persisted()).toBeTruthy();
|
82
|
-
done();
|
83
|
-
});
|
84
|
-
});
|
85
|
-
});
|
86
|
-
});
|
87
|
-
});
|
@@ -1,249 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
// Consider making heavy use of mocks instead;
|
4
|
-
// the tests currently run asynchronously and
|
5
|
-
// heavily influence each other, making them
|
6
|
-
// hard to maintain. As suggested on this page
|
7
|
-
// (https://docs.angularjs.org/guide/unit-testing),
|
8
|
-
// it seems that using mocks enables you to extend
|
9
|
-
// other modules so they are synchronous. Not
|
10
|
-
// sure if that would isolate the tests, but
|
11
|
-
// something is definitely needed to isolate them
|
12
|
-
|
13
|
-
describe('MessagesCtrl', function () {
|
14
|
-
beforeEach(module('entangledTest'));
|
15
|
-
|
16
|
-
var MessagesCtrl,
|
17
|
-
scope,
|
18
|
-
Message;
|
19
|
-
|
20
|
-
beforeEach(inject(function ($controller, $rootScope, $injector) {
|
21
|
-
scope = $rootScope.$new();
|
22
|
-
MessagesCtrl = $controller('MessagesCtrl', {
|
23
|
-
$scope: scope
|
24
|
-
}),
|
25
|
-
Message = $injector.get('Message');
|
26
|
-
}));
|
27
|
-
|
28
|
-
it('assigns a blank message', function() {
|
29
|
-
expect(scope.message).toBeDefined();
|
30
|
-
});
|
31
|
-
|
32
|
-
it('assigns all messages', function(done) {
|
33
|
-
Message.all(function(messages) {
|
34
|
-
expect(messages).toEqual(jasmine.any(Array));
|
35
|
-
done();
|
36
|
-
});
|
37
|
-
});
|
38
|
-
|
39
|
-
it('can find a message', function(done) {
|
40
|
-
// Create message
|
41
|
-
Message.create({ body: 'foo' }, function(message) {
|
42
|
-
// Assert creation was successful
|
43
|
-
expect(message.$persisted()).toBeTruthy();
|
44
|
-
|
45
|
-
// Find message
|
46
|
-
Message.find(message.id, function(message) {
|
47
|
-
expect(message).toBeDefined();
|
48
|
-
done();
|
49
|
-
});
|
50
|
-
});
|
51
|
-
});
|
52
|
-
|
53
|
-
it('can save the blank message', function(done) {
|
54
|
-
setTimeout(function() {
|
55
|
-
var oldLength = scope.messages.length;
|
56
|
-
|
57
|
-
// Assert it's a new message
|
58
|
-
expect(scope.message.id).not.toBeDefined();
|
59
|
-
|
60
|
-
// Be sure to pass validations in the back end
|
61
|
-
scope.message.body = 'foo';
|
62
|
-
|
63
|
-
// Save it
|
64
|
-
scope.message.$save(function() {
|
65
|
-
setTimeout(function() {
|
66
|
-
// Make sure that the message was added to the collection
|
67
|
-
expect(scope.messages.length).toBe(oldLength + 1);
|
68
|
-
|
69
|
-
// Make sure that it has been persisted and new attributes
|
70
|
-
// were sent over from the back end and updated here
|
71
|
-
setTimeout(function() {
|
72
|
-
expect(scope.message.id).toBeDefined();
|
73
|
-
expect(scope.message.created_at).toBeDefined();
|
74
|
-
expect(scope.message.updated_at).toBeDefined();
|
75
|
-
done();
|
76
|
-
}, 100);
|
77
|
-
}, 100);
|
78
|
-
});
|
79
|
-
}, 100);
|
80
|
-
});
|
81
|
-
|
82
|
-
it('can instantiate and save a message in one go with $create', function(done) {
|
83
|
-
Message.create({ body: 'foo' }, function(message) {
|
84
|
-
expect(message.$persisted()).toBeTruthy();
|
85
|
-
done();
|
86
|
-
});
|
87
|
-
});
|
88
|
-
|
89
|
-
it('can update an existing message', function(done) {
|
90
|
-
setTimeout(function() {
|
91
|
-
// Pick first message
|
92
|
-
var message = scope.messages[0];
|
93
|
-
|
94
|
-
// Assert that message has been persisted before
|
95
|
-
expect(message.id).toBeDefined();
|
96
|
-
|
97
|
-
// Remember old updated_at
|
98
|
-
var oldUpdatedAt = message.updated_at;
|
99
|
-
|
100
|
-
// Update it
|
101
|
-
message.body = 'new body';
|
102
|
-
message.$save(function() {
|
103
|
-
setTimeout(function() {
|
104
|
-
// Assert that message was updated across collection
|
105
|
-
expect(scope.messages[0].body).toBe('new body');
|
106
|
-
|
107
|
-
// Assert that message was actually updated in back end
|
108
|
-
// and attributes have been updated here
|
109
|
-
expect(scope.message.updated_at).not.toBe(oldUpdatedAt);
|
110
|
-
done();
|
111
|
-
}, 100);
|
112
|
-
});
|
113
|
-
}, 100);
|
114
|
-
});
|
115
|
-
|
116
|
-
it('gets validation errors', function(done) {
|
117
|
-
setTimeout(function() {
|
118
|
-
// Pick first message
|
119
|
-
var message = scope.messages[0];
|
120
|
-
|
121
|
-
// Assert that message has been persisted before
|
122
|
-
expect(message.id).toBeDefined();
|
123
|
-
|
124
|
-
// Update it so it won't pass validations in the back end
|
125
|
-
message.body = '';
|
126
|
-
|
127
|
-
// Remember old updated_at
|
128
|
-
var oldUpdatedAt = message.updated_at;
|
129
|
-
|
130
|
-
// Save it
|
131
|
-
message.$save(function() {
|
132
|
-
// Assert that message was not updated on server
|
133
|
-
expect(message.updated_at).toBe(oldUpdatedAt);
|
134
|
-
|
135
|
-
// Assert that the message has error messages attached
|
136
|
-
// to it
|
137
|
-
expect(message.errors.body).toEqual(["can't be blank"])
|
138
|
-
|
139
|
-
done();
|
140
|
-
});
|
141
|
-
}, 100);
|
142
|
-
});
|
143
|
-
|
144
|
-
it('checks for validity with $valid()', function() {
|
145
|
-
var message = Message.new();
|
146
|
-
|
147
|
-
// Message should be valid without erros
|
148
|
-
expect(message.$valid()).toBeTruthy();
|
149
|
-
|
150
|
-
message.errors = {
|
151
|
-
body: ["can't be blank"]
|
152
|
-
};
|
153
|
-
|
154
|
-
// Message should not be valid because errors
|
155
|
-
// are attached
|
156
|
-
expect(message.$valid()).not.toBeTruthy();
|
157
|
-
|
158
|
-
// Message should be valid if errors property
|
159
|
-
// present but not filled
|
160
|
-
message.errors = {};
|
161
|
-
expect(message.$valid()).toBeTruthy();
|
162
|
-
});
|
163
|
-
|
164
|
-
it('checks for invalidity with $invalid()', function() {
|
165
|
-
var message = Message.new();
|
166
|
-
|
167
|
-
// Message should not be invalid without errors
|
168
|
-
expect(message.$invalid()).not.toBeTruthy();
|
169
|
-
|
170
|
-
message.errors = {
|
171
|
-
body: ["can't be blank"]
|
172
|
-
};
|
173
|
-
|
174
|
-
// Message should be invalid because errors
|
175
|
-
// are attached
|
176
|
-
expect(message.$invalid()).toBeTruthy();
|
177
|
-
|
178
|
-
// Message should not be invalid if errors property
|
179
|
-
// present but not filled
|
180
|
-
message.errors = {};
|
181
|
-
expect(message.$invalid()).not.toBeTruthy();
|
182
|
-
});
|
183
|
-
|
184
|
-
it('can destroy an existing message', function(done) {
|
185
|
-
setTimeout(function() {
|
186
|
-
// Pick first message
|
187
|
-
var message = scope.messages[0];
|
188
|
-
|
189
|
-
// Assert that message has been persisted before
|
190
|
-
expect(message.id).toBeDefined();
|
191
|
-
|
192
|
-
var oldLength = scope.messages.length;
|
193
|
-
|
194
|
-
message.$destroy(function() {
|
195
|
-
setTimeout(function() {
|
196
|
-
expect(scope.messages.length).toBe(oldLength - 1);
|
197
|
-
done();
|
198
|
-
}, 100);
|
199
|
-
});
|
200
|
-
done();
|
201
|
-
}, 100);
|
202
|
-
});
|
203
|
-
|
204
|
-
it('can destroy a message and receives it in the callback', function(done) {
|
205
|
-
Message.create({ body: 'foo' }, function(message) {
|
206
|
-
expect(message.$persisted()).toBeTruthy();
|
207
|
-
|
208
|
-
message.$destroy(function(message) {
|
209
|
-
expect(message).toBeDefined();
|
210
|
-
done();
|
211
|
-
});
|
212
|
-
});
|
213
|
-
});
|
214
|
-
|
215
|
-
it('can check for persistence', function() {
|
216
|
-
// Instantiate record and mimic persistence
|
217
|
-
var message = Message.new({ id: 1 });
|
218
|
-
|
219
|
-
expect(message.$persisted()).toBeTruthy();
|
220
|
-
});
|
221
|
-
|
222
|
-
it('can check for lack of persistence', function() {
|
223
|
-
// Instantiate record and mimic lack of persistence
|
224
|
-
var message = Message.new({ id: undefined });
|
225
|
-
|
226
|
-
expect(message.$persisted()).not.toBeTruthy();
|
227
|
-
});
|
228
|
-
|
229
|
-
it('can update a message in place', function(done) {
|
230
|
-
// Create message
|
231
|
-
Message.create({ body: 'foo' }, function(message) {
|
232
|
-
// Assert that creation was successful
|
233
|
-
expect(message.$persisted()).toBeTruthy();
|
234
|
-
|
235
|
-
// Remember updated_at
|
236
|
-
var oldUpdatedAt = message.updated_at;
|
237
|
-
|
238
|
-
// Update
|
239
|
-
message.$update({ body: 'new body' }, function() {
|
240
|
-
// Assert that body was updated
|
241
|
-
expect(message.body).toBe('new body');
|
242
|
-
|
243
|
-
// Assert that updated_at is new
|
244
|
-
expect(message.updated_at).not.toEqual(oldUpdatedAt);
|
245
|
-
done();
|
246
|
-
})
|
247
|
-
});
|
248
|
-
});
|
249
|
-
});
|