DG MS; posting to services now works, updated form serializer to handle array attributes.
This commit is contained in:
parent
74e9cd6ca8
commit
fd0065598c
6 changed files with 40 additions and 4 deletions
|
|
@ -14,6 +14,7 @@ class Service < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def public_message(post, length, url = "")
|
||||
Rails.logger.info("Posting out to #{self.class}")
|
||||
url = "" if post.respond_to?(:photos) && post.photos.count == 0
|
||||
space_for_url = url.blank? ? 0 : (url.length + 1)
|
||||
truncated = truncate(post.text(:plain_text => true), :length => (length - space_for_url))
|
||||
|
|
|
|||
|
|
@ -9,7 +9,16 @@ app.forms.Base = app.views.Base.extend({
|
|||
var form = this.$("form");
|
||||
|
||||
function setValueFromField(memo, attribute, selector){
|
||||
memo[attribute] = form.find(selector).val()
|
||||
var selectors = form.find(selector);
|
||||
|
||||
if(selectors.length > 1) {
|
||||
memo[attribute] = _.map(selectors, function(selector){
|
||||
return $(selector).val()
|
||||
})
|
||||
} else {
|
||||
memo[attribute] = selectors.val();
|
||||
}
|
||||
|
||||
return memo
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ app.forms.Post = app.forms.Base.extend({
|
|||
|
||||
formAttrs : {
|
||||
"textarea.text" : "text",
|
||||
"input.aspect_ids" : "aspect_ids"
|
||||
"input.aspect_ids" : "aspect_ids",
|
||||
'input.service:checked' : 'services'
|
||||
},
|
||||
|
||||
initialize : function(){
|
||||
|
|
|
|||
|
|
@ -4,11 +4,20 @@ app.models.StatusMessage = app.models.Post.extend({
|
|||
},
|
||||
|
||||
mungeAndSave : function(){
|
||||
var mungedAttrs = {status_message : _.clone(this.attributes), aspect_ids : mungeAspects(this.get("aspect_ids"))}
|
||||
var mungedAttrs = {
|
||||
status_message : _.clone(this.attributes),
|
||||
aspect_ids : mungeAspects(this.get("aspect_ids")),
|
||||
services : mungeServices(this.get("services"))
|
||||
}
|
||||
|
||||
this.save(mungedAttrs)
|
||||
|
||||
function mungeAspects (value){
|
||||
return [value]
|
||||
}
|
||||
|
||||
function mungeServices (values) {
|
||||
return values.length > 1 ? values : [values]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,4 +13,4 @@ app.pages.PostNew = app.views.Base.extend({
|
|||
saveModel : function(){
|
||||
this.model.mungeAndSave();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,12 +13,28 @@ describe("app.forms.Post", function(){
|
|||
beforeEach(function(){
|
||||
this.view.$("form .text").val("Oh My")
|
||||
this.view.$("form .aspect_ids").val("public")
|
||||
|
||||
/* appending checkboxes */
|
||||
this.view.$("form").append($("<input/>", {
|
||||
value : "fakeBook",
|
||||
checked : "checked",
|
||||
"class" : "service",
|
||||
"type" : "checkbox"
|
||||
}))
|
||||
|
||||
this.view.$("form").append($("<input/>", {
|
||||
value : "twitter",
|
||||
checked : "checked",
|
||||
"class" : "service",
|
||||
"type" : "checkbox"
|
||||
}))
|
||||
})
|
||||
|
||||
it("instantiates a post on form submit", function(){
|
||||
this.view.$("form").submit()
|
||||
expect(this.view.model.get("text")).toBe("Oh My")
|
||||
expect(this.view.model.get("aspect_ids")).toBe("public")
|
||||
expect(this.view.model.get("services").length).toBe(2)
|
||||
})
|
||||
|
||||
it("triggers a 'setFromForm' event", function(){
|
||||
|
|
|
|||
Loading…
Reference in a new issue