Skip to content
Snippets Groups Projects
Commit e77d7608 authored by Dennis Collinson's avatar Dennis Collinson
Browse files

DC DGtoggle between public an private

parent 3a47590d
No related branches found
No related tags found
No related merge requests found
......@@ -5,3 +5,26 @@ end
When /^I write "([^"]*)"$/ do |text|
fill_in :text, :with => text
end
def aspects_dropdown
find(".dropdown-toggle")
end
def select_from_dropdown(option_text, dropdown)
dropdown.click
within ".dropdown-menu" do
link = find("a:contains('#{option_text}')")
link.should be_visible
link.click
end
#assert dropdown text is link
end
When /^I select "([^"]*)" in my aspects dropdown$/ do |title|
within ".aspect_selector" do
select_from_dropdown(title, aspects_dropdown)
end
end
Then /^"([^"]*)" should be a (limited|public) post in my stream$/ do |post_text, scope|
find_post_by_text(post_text).find(".post_scope").text.should =~ /#{scope}/i
end
\ No newline at end of file
......@@ -4,14 +4,19 @@ Feature: Creating a new post
Given a user with username "bob"
And I sign in as "bob@bob.bob"
And I trumpet
And I write "Rectangles are awesome"
Scenario: Posting a public message
And I write "Rectangles are awesome"
When I select "Public" in my aspects dropdown
When I press "Share"
When I go to "/stream"
Then I should see "Rectangles are awesome" as the first post in my stream
And "Rectangles are awesome" should be a public post in my stream
Scenario: Posting to Aspects
When I select "generic" in my aspects dropdown
And I write "This is super skrunkle"
When I select "All Aspects" in my aspects dropdown
And I press "Share"
Then I should see "Rectangles are awesome" as a limited post in my stream
When I go to "/stream"
Then I should see "This is super skrunkle" as the first post in my stream
Then "This is super skrunkle" should be a limited post in my stream
......@@ -7,7 +7,7 @@ app.forms.Post = app.forms.Base.extend({
formAttrs : {
".text" : "text",
// ".aspect_ids" : "aspect_ids"
"input.aspect_ids" : "aspect_ids"
},
initialize : function(){
......
......@@ -4,8 +4,11 @@ app.models.StatusMessage = app.models.Post.extend({
},
mungeAndSave : function(){
var mungedAttrs = {status_message : _.clone(this.attributes), aspect_ids : ["public"]}
var mungedAttrs = {status_message : _.clone(this.attributes), aspect_ids : mungeAspects(this.get("aspect_ids"))}
this.save(mungedAttrs)
function mungeAspects (value){
return [value]
}
}
});
<div class="btn-group aspect_ids check-group">
<div class="btn-group aspects_dropdown check-group">
<a class="btn btn-info dropdown-toggle" data-toggle="dropdown" href="#">All Aspects <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>
<label class="checkbox">
<input type="checkbox" value="public"/>Public
</label>
</li>
<li>
<label class="checkbox">
<input type="checkbox" value="all"/>All Aspects
</label>
</li>
<li class="divider"></li>
<li><a href="#" class="public" data-visibility="public">Public</a></li>
<li><a href="#" class="all-aspects" data-visibility="all-aspects">All Aspects</a></li>
<!--<li class="divider"></li>-->
<!--<li><a href="#" data-value="custom">Custom</a></li>-->
</ul>
</div>
{{#each current_user.aspects}}
<input type="hidden" class="aspect_ids"/>
<li>
<label class="checkbox">
<input type="checkbox" value="{{id}}"/> {{name}}
</label>
</li>
{{/each}}
</ul>
</div>
\ No newline at end of file
<!--<select multiple=multiple>-->
<!--{{#each current_user.aspects}}-->
<!--<option value="{{id}}"> {{name}}</option>-->
<!--{{/each}}-->
<!--</select>-->
\ No newline at end of file
......@@ -2,10 +2,10 @@
<div class='span12'>
<form class="new-post well">
<label>text<textarea class="text"/></label>
<input type="submit" class="btn-primary" value="Share"></input>
<div class="aspect_selector"/>
<br/>
<input type="submit" class="btn-primary" value="Share"></input>
</form>
</div>
</div>
app.views.AspectsDropdown = app.views.Base.extend({
templateName : "aspects-dropdown"
templateName : "aspects-dropdown",
events : {
"click .dropdown-menu a" : "setVisibility"
},
setVisibility : function(evt){
var linkVisibility = $(evt.target).data("visibility")
, visibilityCallbacks = {
'public' : setPublic,
'all-aspects' : setPrivate
}
visibilityCallbacks[linkVisibility].call(this)
function setPublic (){
this.setAspectIds("public")
}
function setPrivate (){
this.setAspectIds("all_aspects")
}
},
setAspectIds : function(val){
this.$("input.aspect_ids").val(val)
}
})
\ No newline at end of file
......@@ -12,11 +12,13 @@ describe("app.forms.Post", function(){
describe("submitting a valid form", function(){
beforeEach(function(){
this.view.$("form .text").val("Oh My")
this.view.$("form .aspect_ids").val("public")
})
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")
})
it("triggers a 'setFromForm' event", function(){
......
describe("app.views.AspectsDropdown", function(){
beforeEach(function(){
this.view = new app.views.AspectsDropdown
})
describe("rendering", function(){
beforeEach(function(){
this.view.render()
})
describe("selecting Public", function(){
it("calls set aspect_ids to 'public'", function(){
this.view.$("a[data-visibility='public']").click()
expect(this.view.$("input.aspect_ids").val()).toBe("public")
})
})
describe("selecting All Aspects", function(){
it("calls set aspect_ids to 'all'", function(){
this.view.$("a[data-visibility='all-aspects']").click()
expect(this.view.$("input.aspect_ids").val()).toBe("all_aspects")
})
})
})
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment