upgrade backbone, fix tests

some cukes may be failing non deterministically, I think, do we bump the cuke timeout?
This commit is contained in:
danielgrippi 2012-04-03 16:31:17 -07:00
parent fb946bd407
commit 3bc3f13651
17 changed files with 763 additions and 466 deletions

View file

@ -1,7 +1,11 @@
app.collections.Comments = Backbone.Collection.extend({ app.collections.Comments = Backbone.Collection.extend({
model: app.models.Comment, model: app.models.Comment,
url : function(){
return this.post.url() + "/comments"
},
initialize : function(models, options) { initialize : function(models, options) {
this.url = "/posts/" + options.post.id + "/comments" //not delegating to post.url() because when it is in a stream collection it delegates to that url this.post = options.post
} }
}); });

View file

@ -91,6 +91,20 @@ app.models.Post = Backbone.Model.extend({
}}); }});
}, },
comment : function (text) {
var self = this
, postComments = this.comments;
postComments.create({"text": text}, {
url : postComments.url(),
wait:true, // added a wait for the time being. 0.5.3 was not optimistic, but 0.9.2 is.
error:function () {
alert(Diaspora.I18n.t("failed_to_post_message"));
}
});
},
headline : function() { headline : function() {
var headline = this.get("text").trim() var headline = this.get("text").trim()
, newlineIdx = headline.lastIndexOf("\n") , newlineIdx = headline.lastIndexOf("\n")

View file

@ -44,7 +44,6 @@ app.pages.PostViewer = app.views.Base.extend({
postRenderTemplate : function() { postRenderTemplate : function() {
/* set the document title */ /* set the document title */
console.log(this.model)
document.title = this.model.get("title"); document.title = this.model.get("title");
this.bindNavHooks(); this.bindNavHooks();

View file

@ -6,7 +6,9 @@ app.Router = Backbone.Router.extend({
"participate": "stream", "participate": "stream",
"explore": "stream", "explore": "stream",
"aspects": "stream",
"aspects:query": "stream", "aspects:query": "stream",
"commented": "stream", "commented": "stream",
"liked": "stream", "liked": "stream",
"mentions": "stream", "mentions": "stream",

View file

@ -38,15 +38,7 @@ app.views.CommentStream = app.views.Base.extend({
createComment: function(evt) { createComment: function(evt) {
if(evt){ evt.preventDefault(); } if(evt){ evt.preventDefault(); }
this.model.comment(this.$(".comment_box").val());
this.model.comments.create({
"text" : this.$(".comment_box").val()
}, {
error: function() {
alert(Diaspora.I18n.t("failed_to_post_message"));
}
});
this.$(".comment_box").val("") this.$(".comment_box").val("")
return this; return this;
}, },

View file

@ -9,6 +9,10 @@ app.views.PostViewerNewComment = app.views.Base.extend({
scrollableArea : "#post-reactions", scrollableArea : "#post-reactions",
initialize : function(){
this.model.comments.bind("sync", this.clearAndReactivateForm, this)
},
postRenderTemplate : function() { postRenderTemplate : function() {
this.$("textarea").placeholder(); this.$("textarea").placeholder();
this.$("textarea").autoResize({'extraSpace' : 0}); this.$("textarea").autoResize({'extraSpace' : 0});
@ -16,14 +20,8 @@ app.views.PostViewerNewComment = app.views.Base.extend({
createComment: function(evt) { createComment: function(evt) {
if(evt){ evt.preventDefault(); } if(evt){ evt.preventDefault(); }
var self = this;
this.toggleFormState() this.toggleFormState()
this.model.comments.create({ this.model.comment(this.$("textarea").val());
"text" : this.$("textarea").val()
}, {success : _.bind(self.clearAndReactivateForm, self)});
}, },
clearAndReactivateForm : function() { clearAndReactivateForm : function() {

View file

@ -5,8 +5,11 @@ Feature: The activity stream
When I sign in as "bob@bob.bob" When I sign in as "bob@bob.bob"
And I post "A- I like turtles" And I post "A- I like turtles"
And I wait for 1 second
And I post "B- barack obama is your new bicycle" And I post "B- barack obama is your new bicycle"
And I wait for 1 second
And I post "C- barack obama is a square" And I post "C- barack obama is a square"
And I wait for 1 second
When I go to the activity stream page When I go to the activity stream page
Then "C- barack obama is a square" should be post 1 Then "C- barack obama is a square" should be post 1

View file

@ -45,6 +45,7 @@ Feature: following and being followed
And I am on "bob@bob.bob"'s page And I am on "bob@bob.bob"'s page
And I add the person to my "Besties" aspect And I add the person to my "Besties" aspect
And I wait for the ajax to finish
And I add the person to my "Unicorns" aspect And I add the person to my "Unicorns" aspect
When I go to the home page When I go to the home page

View file

@ -17,12 +17,12 @@ Feature: posting from the main page
Scenario: post a text-only message to all aspects Scenario: post a text-only message to all aspects
Given I expand the publisher Given I expand the publisher
When I fill in "status_message_fake_text" with "I am eating a yogurt" When I fill in "status_message_fake_text" with "I am eating yogurt"
And I press "Share" And I press "Share"
And I wait for the ajax to finish And I wait for the ajax to finish
And I go to the aspects page And I go to the aspects page
Then I should see "I am eating a yogurt" within ".stream_element" Then "I am eating yogurt" should be post 1
Scenario: posting a message appends it to the top of the stream Scenario: posting a message appends it to the top of the stream
When I click the publisher and post "sup dog" When I click the publisher and post "sup dog"

View file

@ -7,7 +7,7 @@ Then /^I like the post "([^"]*)"$/ do |post_text|
end end
Then /^"([^"]*)" should be post (\d+)$/ do |post_text, position| Then /^"([^"]*)" should be post (\d+)$/ do |post_text, position|
find(".stream_element:nth-child(#{position}) .post-content").text.should == post_text stream_element_numbers_content(position).text.should == post_text
end end
When /^I toggle nsfw posts$/ do When /^I toggle nsfw posts$/ do

View file

@ -99,11 +99,10 @@ Then /^I should have (\d) contacts? in "([^"]*)"$/ do |n_contacts, aspect_name|
end end
When /^I (?:add|remove) the person (?:to|from) my "([^\"]*)" aspect$/ do |aspect_name| When /^I (?:add|remove) the person (?:to|from) my "([^\"]*)" aspect$/ do |aspect_name|
steps %Q{ aspects_dropdown = find(".aspect_membership .toggle.button:first")
And I press the first ".toggle.button" aspects_dropdown.click
And I click on selector ".dropdown.active .dropdown_list li[data-aspect_id=#{@me.aspects.where(:name => aspect_name).first.id}]" find(".dropdown.active .dropdown_list li:contains('#{aspect_name}')").click
And I press the first ".toggle.button" aspects_dropdown.click
}
end end
When /^I post a status with the text "([^\"]*)"$/ do |text| When /^I post a status with the text "([^\"]*)"$/ do |text|

View file

@ -65,6 +65,13 @@ Spork.prefork do
require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_resque") require File.join(File.dirname(__FILE__), "..", "..", "spec", "support", "fake_resque")
require File.join(File.dirname(__FILE__), 'run_resque_in_process') require File.join(File.dirname(__FILE__), 'run_resque_in_process')
#hax to get rubymine to run spork, set RUBYMINE_HOME in your .bash_profile
if ENV["RUBYMINE_HOME"]
puts "Loading rubymine spork extensions"
$:.unshift(File.expand_path("rb/testing/patch/common", ENV["RUBYMINE_HOME"]))
$:.unshift(File.expand_path("rb/testing/patch/bdd", ENV["RUBYMINE_HOME"]))
end
end end
Spork.each_run do Spork.each_run do

View file

@ -34,7 +34,11 @@ module PublishingCukeHelpers
end end
def first_post_text def first_post_text
find('.stream_element:first .post-content').text() stream_element_numbers_content(1).text()
end
def stream_element_numbers_content(position)
find(".stream_element:nth-child(#{position}) .post-content")
end end
def find_post_by_text(text) def find_post_by_text(text)

View file

@ -3,7 +3,7 @@ describe("app.collections.comments", function(){
it("should user the post id", function(){ it("should user the post id", function(){
var post =new app.models.Post({id : 5}) var post =new app.models.Post({id : 5})
var collection = new app.collections.Comments([], {post : post}) var collection = new app.collections.Comments([], {post : post})
expect(collection.url).toBe("/posts/5/comments") expect(collection.url()).toBe("/posts/5/comments")
}) })
}) })
}) })

View file

@ -1,12 +1,12 @@
describe("app.views.AspectsDropdown", function(){ describe("app.views.AspectsDropdown", function(){
beforeEach(function(){ beforeEach(function(){
loginAs(factory.user({ loginAs({
aspects : [ aspects : [
{ id : 3, name : "sauce" }, { id : 3, name : "sauce" },
{ id : 5, name : "conf" }, { id : 5, name : "conf" },
{ id : 7, name : "lovers" } { id : 7, name : "lovers" }
] ]
})) })
this.view = new app.views.AspectsDropdown this.view = new app.views.AspectsDropdown
}) })
@ -62,7 +62,9 @@ describe("app.views.AspectsDropdown", function(){
describe("selecting An Aspect", function(){ describe("selecting An Aspect", function(){
beforeEach(function(){ beforeEach(function(){
this.link = this.view.$("a:contains('lovers')") this.link = this.view.$("a:contains('lovers')")
console.log(app.currentUser.get("aspects"), $("a:contains('lovers')", this.view.el))
this.link.click() this.link.click()
}) })

View file

@ -1,10 +1,10 @@
describe("app.views.ServicesSelector", function(){ describe("app.views.ServicesSelector", function(){
beforeEach(function(){ beforeEach(function(){
loginAs(factory.user({ loginAs({
services : [ services : [
{ provider : "fakeBook" } { provider : "fakeBook" }
] ]
})); });
this.view = new app.views.ServicesSelector(); this.view = new app.views.ServicesSelector();
}); });
@ -16,7 +16,6 @@ describe("app.views.ServicesSelector", function(){
it("displays all services", function(){ it("displays all services", function(){
var checkboxes = $(this.view.el).find('input[type="checkbox"]'); var checkboxes = $(this.view.el).find('input[type="checkbox"]');
expect(checkboxes.val()).toBe("fakeBook"); expect(checkboxes.val()).toBe("fakeBook");
}); });
}); });

File diff suppressed because it is too large Load diff