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
|
||||
And I write "Rectangles are awesome"
|
||||
And I press "Share"
|
||||
# When I go to the stream page
|
||||
# Then I should see "Rectangles are awesome" as the first post in my stream
|
||||
When I go to "/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"},
|
||||
|
||||
initialize : function(){
|
||||
console.log("In the page")
|
||||
|
||||
this.model = new app.models.Post()
|
||||
this.model = new app.models.StatusMessage()
|
||||
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">
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,25 @@
|
|||
app.views.PostForm = app.views.Base.extend({
|
||||
templateName : "post-form",
|
||||
|
||||
initialize : function(){
|
||||
console.log("In the form")
|
||||
events :{
|
||||
'submit form' : 'setModelAttributes'
|
||||
},
|
||||
|
||||
postRenderTemplate: function(){
|
||||
console.log("I'm getting rendered")
|
||||
}
|
||||
formAttrs : {
|
||||
".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")
|
||||
}
|
||||
});
|
||||
|
|
@ -3,20 +3,16 @@ describe("app", function() {
|
|||
it("sets the user if given one and returns the current user", function() {
|
||||
expect(app.user()).toBeFalsy()
|
||||
});
|
||||
|
||||
|
||||
it("returns false if the current_user isn't set", function() {
|
||||
app._user = undefined;
|
||||
|
||||
expect(app.user()).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('currentUser', 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"});
|
||||
|
||||
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(){
|
||||
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})
|
||||
})
|
||||
|
||||
it("renders", function(){
|
||||
describe("rendering", function(){
|
||||
beforeEach(function(){
|
||||
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