MS DC posting from post/new werks
This commit is contained in:
parent
ab35f2bf3d
commit
bf4dabc4f4
9 changed files with 84 additions and 21 deletions
|
|
@ -8,5 +8,5 @@ Feature: Creating a new post
|
||||||
When I trumpet
|
When I trumpet
|
||||||
And I write "Rectangles are awesome"
|
And I write "Rectangles are awesome"
|
||||||
And I press "Share"
|
And I press "Share"
|
||||||
# When I go to the stream page
|
When I go to "/stream"
|
||||||
# Then I should see "Rectangles are awesome" as the first post in my stream
|
Then I should see "Rectangles are awesome" as the first post in my stream
|
||||||
|
|
|
||||||
|
|
@ -1 +1,11 @@
|
||||||
app.models.StatusMessage = app.models.Post.extend({ });
|
app.models.StatusMessage = app.models.Post.extend({
|
||||||
|
url : function(){
|
||||||
|
return this.isNew() ? '/status_messages' : '/posts/' + this.get("id");
|
||||||
|
},
|
||||||
|
|
||||||
|
mungeAndSave : function(){
|
||||||
|
var mungedAttrs = {status_message : _.clone(this.attributes), aspect_ids : ["public"]}
|
||||||
|
|
||||||
|
this.save(mungedAttrs)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,13 @@ app.pages.PostNew = app.views.Base.extend({
|
||||||
subviews : { "#new-post" : "postForm"},
|
subviews : { "#new-post" : "postForm"},
|
||||||
|
|
||||||
initialize : function(){
|
initialize : function(){
|
||||||
console.log("In the page")
|
this.model = new app.models.StatusMessage()
|
||||||
|
|
||||||
this.model = new app.models.Post()
|
|
||||||
this.postForm = new app.views.PostForm({model : this.model})
|
this.postForm = new app.views.PostForm({model : this.model})
|
||||||
|
|
||||||
|
this.model.bind("setFromForm", this.saveModel, this)
|
||||||
|
},
|
||||||
|
|
||||||
|
saveModel : function(){
|
||||||
|
this.model.mungeAndSave();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<form class="new-post">
|
<form class="new-post">
|
||||||
<label>text<textarea class="text"/></label>
|
<label>text<textarea class="text"/></label>
|
||||||
<input type="submit" value="Share" class="btn-primary"></input>
|
<input type="submit" class="btn-primary" value="Share"></input>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,25 @@
|
||||||
app.views.PostForm = app.views.Base.extend({
|
app.views.PostForm = app.views.Base.extend({
|
||||||
templateName : "post-form",
|
templateName : "post-form",
|
||||||
|
|
||||||
initialize : function(){
|
events :{
|
||||||
console.log("In the form")
|
'submit form' : 'setModelAttributes'
|
||||||
},
|
},
|
||||||
|
|
||||||
postRenderTemplate: function(){
|
formAttrs : {
|
||||||
console.log("I'm getting rendered")
|
".text" : "text"
|
||||||
|
},
|
||||||
|
|
||||||
|
setModelAttributes : function(evt){
|
||||||
|
if(evt){ evt.preventDefault(); }
|
||||||
|
|
||||||
|
var form = this.$("form");
|
||||||
|
|
||||||
|
function setValueFromField(memo, attribute, selector){
|
||||||
|
memo[attribute] = form.find(selector).val()
|
||||||
|
return memo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.model.set(_.inject(this.formAttrs, setValueFromField, {}))
|
||||||
|
this.model.trigger("setFromForm")
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -6,17 +6,13 @@ describe("app", function() {
|
||||||
|
|
||||||
it("returns false if the current_user isn't set", function() {
|
it("returns false if the current_user isn't set", function() {
|
||||||
app._user = undefined;
|
app._user = undefined;
|
||||||
|
|
||||||
expect(app.user()).toEqual(false);
|
expect(app.user()).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('currentUser', function(){
|
|
||||||
it("sets the user if given one and returns the current user", function() {
|
it("sets the user if given one and returns the current user", function() {
|
||||||
expect(app.currentUser.authenticated()).toBeFalsy()
|
expect(app.user()).toBeFalsy()
|
||||||
app.user({name: "alice"});
|
app.user({name: "alice"});
|
||||||
|
|
||||||
expect(app.user().get("name")).toEqual("alice");
|
expect(app.user().get("name")).toEqual("alice");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
|
|
||||||
12
spec/javascripts/app/models/status_message_spec.js
Normal file
12
spec/javascripts/app/models/status_message_spec.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
describe("app.models.StatusMessage", function(){
|
||||||
|
describe("#url", function(){
|
||||||
|
it("is /status_messages when its new", function(){
|
||||||
|
var post = new app.models.StatusMessage()
|
||||||
|
expect(post.url()).toBe("/status_messages")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("is /posts/id when it has an id", function(){
|
||||||
|
expect(new app.models.StatusMessage({id : 5}).url()).toBe("/posts/5")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -6,4 +6,12 @@ describe("app.pages.PostNew", function(){
|
||||||
it("renders", function(){
|
it("renders", function(){
|
||||||
this.page.render();
|
this.page.render();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
context("when the model receives setFromForm", function(){
|
||||||
|
it("it calls mungeAndSave", function(){
|
||||||
|
spyOn(this.page.model, "mungeAndSave")
|
||||||
|
this.page.model.trigger("setFromForm")
|
||||||
|
expect(this.page.model.mungeAndSave).toHaveBeenCalled();
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
@ -4,7 +4,27 @@ describe("app.views.PostForm", function(){
|
||||||
this.view = new app.views.PostForm({model : this.post})
|
this.view = new app.views.PostForm({model : this.post})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("renders", function(){
|
describe("rendering", function(){
|
||||||
|
beforeEach(function(){
|
||||||
this.view.render()
|
this.view.render()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("submitting a valid form", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.view.$("form .text").val("Oh My")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("instantiates a post on form submit", function(){
|
||||||
|
this.view.$("form").submit()
|
||||||
|
expect(this.view.model.get("text")).toBe("Oh My")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("triggers a 'setFromForm' event", function(){
|
||||||
|
var spy = jasmine.createSpy();
|
||||||
|
this.view.model.bind("setFromForm", spy);
|
||||||
|
this.view.$("form").submit();
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
Loading…
Reference in a new issue