Skip to content

Commit

Permalink
Improve link to original post in reshared polls
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen van Bergerem committed Mar 15, 2015
1 parent 9589cb2 commit 81cd175
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
16 changes: 10 additions & 6 deletions app/assets/javascripts/app/views/poll_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ app.views.Poll = app.views.Base.extend({

presenter: function(){
var defaultPresenter = this.defaultPresenter();
var isResharePost = (this.model.get('post_type') == 'Reshare');
var show_form = defaultPresenter.loggedIn &&
!isResharePost &&
!this.model.get('already_participated_in_poll');
var isReshare = (this.model.get('post_type') === 'Reshare');
var showForm = defaultPresenter.loggedIn &&
!isReshare &&
!this.model.get('already_participated_in_poll');
var originalPostLink = isReshare && this.model.get('root') ?
'<a href="/posts/' + this.model.get('root').id + '" class="root_post_link">' + Diaspora.I18n.t('poll.original_post') + '</a>' :
'';

return _.extend(defaultPresenter, {
show_form: show_form,
is_reshare_post: isResharePost
show_form: showForm,
is_reshare: isReshare,
original_post_link: originalPostLink
});
},

Expand Down
4 changes: 2 additions & 2 deletions app/assets/templates/poll_tpl.jst.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
{{/poll.poll_answers}}
{{/if}}

{{#if is_reshare_post }}
{{#if is_reshare }}
<div class="poll_footer">
<a class="root_post_link" href="/posts/{{root.id}}">{{t "poll.vote_original_post" }}</a>
{{{t "poll.go_to_original_post" original_post_link=original_post_link}}}
</div>
{{/if}}

Expand Down
3 changes: 2 additions & 1 deletion config/locales/javascript/javascript.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ en:

poll:
vote: "Vote"
vote_original_post: 'Vote original post'
go_to_original_post: "You can participate in this poll on the <%= original_post_link %>."
original_post: "original post"
result: "Result"
count:
one: "1 vote so far"
Expand Down
23 changes: 16 additions & 7 deletions features/desktop/reshare.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ Feature: public repost
| Alice Smith | alice@alice.alice |
| Eve Doe | eve@eve.eve |
And a user with email "[email protected]" is connected with "[email protected]"
And a user with email "[email protected]" is connected with "[email protected]"
And "[email protected]" has a public post with text "reshare this!"

Scenario: Resharing a post from a single post page
Given "[email protected]" has a public post with text "reshare this!"
And I sign in as "[email protected]"
Given I sign in as "[email protected]"
And I am on "[email protected]"'s page
And I open the show page of the "reshare this!" post
And I click on selector "a.reshare"
Expand All @@ -23,8 +24,7 @@ Feature: public repost
And I should see a flash message containing "successfully"

Scenario: Resharing a post from a single post page that is reshared
Given "[email protected]" has a public post with text "reshare this!"
And the post with text "reshare this!" is reshared by "[email protected]"
Given the post with text "reshare this!" is reshared by "[email protected]"
And I sign in as "[email protected]"
And I am on "[email protected]"'s page
And I open the show page of the "reshare this!" post
Expand All @@ -33,12 +33,21 @@ Feature: public repost
Then I should see a flash message indicating success
And I should see a flash message containing "successfully"

Scenario: Delete original reshared post
Given "[email protected]" has a public post with text "Don't reshare this!"
And the post with text "Don't reshare this!" is reshared by "[email protected]"
And I sign in as "[email protected]"
And I am on "[email protected]"'s page

When I click to delete the first post
And I log out
And I sign in as "[email protected]"
Then I should see "Original post deleted by author" within ".reshare"

# should be covered in rspec, so testing that the post is added to
# app.stream in jasmine should be enough coverage
Scenario: When I reshare, it shows up on my profile page
Given "[email protected]" has a public post with text "reshare this!"
And I sign in as "[email protected]"

Given I sign in as "[email protected]"
And I follow "Reshare"
And I confirm the alert
Then I should see a flash message indicating success
Expand Down
22 changes: 14 additions & 8 deletions spec/javascripts/app/views/poll_view_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,33 +44,39 @@ describe("app.views.Poll", function(){
});
});

describe('reshared post', function(){
describe("reshared post", function(){
beforeEach(function(){
this.view.model.set('post_type', 'Reshare');
this.view.model.set('root', {id: 1});
Diaspora.I18n.load({
poll: {
go_to_original_post: "You can participate in this poll on the <%= original_post_link %>.",
original_post: "original post"
}
});
this.view.model.attributes.post_type = "Reshare";
this.view.model.attributes.root = {id: 1};
this.view.render();
});

it('hide vote form', function(){
it("hides the vote form", function(){
expect(this.view.$('form').length).toBe(0);
});

it("show a.root_post_link", function(){
it("shows a.root_post_link", function(){
var id = this.view.model.get('root').id;
expect(this.view.$('a.root_post_link').attr('href')).toBe('/posts/'+id);
});
});

describe("vote form", function(){
it('show vote form when user is logged in and not voted before', function(){
it("shows vote form when user is logged in and not voted before", function(){
expect(this.view.$('form').length).toBe(1);
});
it('hide vote form when user voted before', function(){
it("hides vote form when user voted before", function(){
this.view.model.attributes.already_participated_in_poll = true;
this.view.render();
expect(this.view.$('form').length).toBe(0);
});
it("hide vote form when user not logged in", function(){
it("hides vote form when user not logged in", function(){
logout();
this.view.render();
expect(this.view.$('form').length).toBe(0);
Expand Down
2 changes: 1 addition & 1 deletion spec/models/reshare_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
end

it 'contains root poll' do
@reshare.poll == @root_post.poll
expect(@reshare.poll).to eq @root_post.poll
end
end

Expand Down

0 comments on commit 81cd175

Please sign in to comment.