diff --git a/Changelog.md b/Changelog.md index af210c483..8aa461f4e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -198,6 +198,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a * Expose participation controls in the stream view [#5511](https://github.com/diaspora/diaspora/pull/5511) * Reimplement photo export [#5685](https://github.com/diaspora/diaspora/pull/5685) * Add participation controls in the single post view [#5722](https://github.com/diaspora/diaspora/pull/5722) +* Display polls on reshares [#5782](https://github.com/diaspora/diaspora/pull/5782) # 0.4.1.2 diff --git a/app/assets/javascripts/app/views/poll_view.js b/app/assets/javascripts/app/views/poll_view.js index 1ec3d1869..14355716d 100644 --- a/app/assets/javascripts/app/views/poll_view.js +++ b/app/assets/javascripts/app/views/poll_view.js @@ -14,11 +14,18 @@ app.views.Poll = app.views.Base.extend({ presenter: function(){ var defaultPresenter = this.defaultPresenter(); - var show_form = defaultPresenter.loggedIn && - !this.model.attributes.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') ? + '' + Diaspora.I18n.t('poll.original_post') + '' : + ''; return _.extend(defaultPresenter, { - show_form: show_form + show_form: showForm, + is_reshare: isReshare, + original_post_link: originalPostLink }); }, @@ -97,7 +104,7 @@ app.views.Poll = app.views.Base.extend({ var pollParticipation = new app.models.PollParticipation({ poll_answer_id: answer_id, poll_id: this.poll.poll_id, - post_id: this.poll.post_id, + post_id: this.poll.post_id, }); var _this = this; diff --git a/app/assets/templates/poll_tpl.jst.hbs b/app/assets/templates/poll_tpl.jst.hbs index f9aad7f18..4b73b1a86 100644 --- a/app/assets/templates/poll_tpl.jst.hbs +++ b/app/assets/templates/poll_tpl.jst.hbs @@ -37,6 +37,13 @@ {{/poll.poll_answers}} {{/if}} + + {{#if is_reshare }} +
+ {{/if}} + {{/if}} diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 7e8fac45b..c10cde1f0 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -49,6 +49,10 @@ class Reshare < Post absolute_root.try(:location).try(:address) end + def poll + absolute_root.try(:poll) || super + end + def receive(recipient, sender) local_reshare = Reshare.where(:guid => self.guid).first if local_reshare && local_reshare.root.author_id == recipient.person.id diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index 03d7e5337..cf869a965 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -227,6 +227,8 @@ en: poll: vote: "Vote" + 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" diff --git a/features/desktop/reshare.feature b/features/desktop/reshare.feature index 928813e49..26c760be5 100644 --- a/features/desktop/reshare.feature +++ b/features/desktop/reshare.feature @@ -11,10 +11,11 @@ Feature: public repost | Alice Smith | alice@alice.alice | | Eve Doe | eve@eve.eve | And a user with email "bob@bob.bob" is connected with "alice@alice.alice" + And a user with email "eve@eve.eve" is connected with "bob@bob.bob" + And "bob@bob.bob" has a public post with text "reshare this!" Scenario: Resharing a post from a single post page - Given "bob@bob.bob" has a public post with text "reshare this!" - And I sign in as "alice@alice.alice" + Given I sign in as "alice@alice.alice" And I am on "bob@bob.bob"'s page And I open the show page of the "reshare this!" post And I click on selector "a.reshare" @@ -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 "bob@bob.bob" has a public post with text "reshare this!" - And the post with text "reshare this!" is reshared by "eve@eve.eve" + Given the post with text "reshare this!" is reshared by "eve@eve.eve" And I sign in as "alice@alice.alice" And I am on "bob@bob.bob"'s page And I open the show page of the "reshare this!" post @@ -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 "alice@alice.alice" has a public post with text "Don't reshare this!" + And the post with text "Don't reshare this!" is reshared by "bob@bob.bob" + And I sign in as "alice@alice.alice" + And I am on "alice@alice.alice"'s page + + When I click to delete the first post + And I log out + And I sign in as "bob@bob.bob" + 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 "bob@bob.bob" has a public post with text "reshare this!" - And I sign in as "alice@alice.alice" - + Given I sign in as "alice@alice.alice" And I follow "Reshare" And I confirm the alert Then I should see a flash message indicating success diff --git a/spec/javascripts/app/views/poll_view_spec.js b/spec/javascripts/app/views/poll_view_spec.js index 8f86d6eb3..31372dca5 100644 --- a/spec/javascripts/app/views/poll_view_spec.js +++ b/spec/javascripts/app/views/poll_view_spec.js @@ -44,16 +44,39 @@ describe("app.views.Poll", function(){ }); }); + describe("reshared post", function(){ + beforeEach(function(){ + 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("hides the vote form", function(){ + expect(this.view.$('form').length).toBe(0); + }); + + 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); diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index ecc24c9de..86da365db 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -63,6 +63,17 @@ describe Reshare, :type => :model do end end + describe '#poll' do + before do + @root_post = FactoryGirl.create(:status_message_with_poll, public: true) + @reshare = FactoryGirl.create(:reshare, root: @root_post) + end + + it 'contains root poll' do + expect(@reshare.poll).to eq @root_post.poll + end + end + describe '#notification_type' do before do sm = FactoryGirl.build(:status_message, :author => alice.person, :public => true)