forked from jasonm/backbone_sync-rails
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
453ee2a
commit 4c67f34
Showing
13 changed files
with
124 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class BackboneSyncObserver < ActiveRecord::Observer | ||
observe :task, :comment | ||
include BackboneSync::Rails::Faye::Observer | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Comment < ActiveRecord::Base | ||
belongs_to :task | ||
|
||
def faye_channel | ||
"tasks/#{task.id}/comments" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
class Task < ActiveRecord::Base | ||
has_many :comments | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateComments < ActiveRecord::Migration | ||
def change | ||
create_table :comments do |t| | ||
t.text :body | ||
t.integer :task_id | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,103 @@ | ||
require 'spec_helper' | ||
|
||
describe BackboneSync::Rails::Faye::Observer do | ||
it 'broadcasts updates over a Faye channel' do | ||
task = Factory(:task, title: 'Old Title') | ||
new_attributes = Factory.attributes_for(:task, title: 'New Title') | ||
task.update_attributes(new_attributes) | ||
|
||
expected_attributes = JSON.parse(task.to_json) | ||
|
||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks", | ||
"data" => { | ||
"update" => { | ||
task.id.to_s => expected_attributes | ||
context 'Default model subchannel settings' do | ||
it 'broadcasts updates over a Faye channel' do | ||
task = Factory(:task, title: 'Old Title') | ||
new_attributes = Factory.attributes_for(:task, title: 'New Title') | ||
task.update_attributes(new_attributes) | ||
|
||
expected_attributes = JSON.parse(task.to_json) | ||
|
||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks", | ||
"data" => { | ||
"update" => { | ||
task.id.to_s => expected_attributes | ||
} | ||
} | ||
} | ||
}) | ||
end | ||
}) | ||
end | ||
|
||
it 'broadcasts destroys over a Faye channel' do | ||
task = Factory(:task, title: 'Old Title') | ||
task.destroy | ||
|
||
it 'broadcasts destroys over a Faye channel' do | ||
task = Factory(:task, title: 'Old Title') | ||
task.destroy | ||
expected_attributes = JSON.parse(task.to_json) | ||
|
||
expected_attributes = JSON.parse(task.to_json) | ||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks", | ||
"data" => { | ||
"destroy" => { | ||
task.id.to_s => expected_attributes | ||
} | ||
} | ||
}) | ||
end | ||
|
||
it 'broadcasts creates over a Faye channel' do | ||
task = Factory(:task) | ||
expected_attributes = JSON.parse(task.to_json) | ||
|
||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks", | ||
"data" => { | ||
"destroy" => { | ||
task.id.to_s => expected_attributes | ||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks", | ||
"data" => { | ||
"create" => { | ||
task.id.to_s => expected_attributes | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
end | ||
end | ||
|
||
it 'broadcasts creates over a Faye channel' do | ||
task = Factory(:task) | ||
expected_attributes = JSON.parse(task.to_json) | ||
context 'Model that is set in a child relationship' do | ||
let(:task) { Factory(:task) } | ||
|
||
it 'broadcasts updates over a Faye channel' do | ||
comment = Factory(:comment, task: task, body: 'this body isn\'t too great') | ||
new_attributes = Factory.attributes_for(:comment, body: 'I like this body') | ||
comment.update_attributes(new_attributes) | ||
|
||
expected_attributes = JSON.parse(comment.to_json) | ||
|
||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks/#{task.id}/comments", | ||
"data" => { | ||
"update" => { | ||
comment.id.to_s => expected_attributes | ||
} | ||
} | ||
}) | ||
end | ||
|
||
it 'broadcasts destroys over a Faye channel' do | ||
comment = Factory(:comment, task: task) | ||
comment.destroy | ||
|
||
expected_attributes = JSON.parse(comment.to_json) | ||
|
||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks/#{task.id}/comments", | ||
"data" => { | ||
"destroy" => { | ||
comment.id.to_s => expected_attributes | ||
} | ||
} | ||
}) | ||
end | ||
|
||
it 'broadcasts creates over a Faye channel' do | ||
comment = Factory(:comment, task: task) | ||
expected_attributes = JSON.parse(comment.to_json) | ||
|
||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks", | ||
"data" => { | ||
"create" => { | ||
task.id.to_s => expected_attributes | ||
FakeFayeServer.messages.should include({ | ||
"channel" => "/sync/tasks/#{task.id}/comments", | ||
"data" => { | ||
"create" => { | ||
comment.id.to_s => expected_attributes | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters