From e36b59309f0f61954686878ccd32a6fa0e98e746 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 27 Aug 2017 04:20:19 +0200 Subject: [PATCH 01/16] Remove xml format from posts controller closes #7584 --- app/controllers/posts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 9d6b3258c..3194c1b59 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -6,7 +6,7 @@ class PostsController < ApplicationController before_action :authenticate_user!, only: %i(destroy mentionable) before_action :set_format_if_malformed_from_status_net, only: :show - respond_to :html, :mobile, :json, :xml + respond_to :html, :mobile, :json rescue_from Diaspora::NonPublic do authenticate_user! From 51152e140d0e5ad832555f5e157258232f0a6491 Mon Sep 17 00:00:00 2001 From: goobertron Date: Tue, 22 Aug 2017 19:11:38 +0100 Subject: [PATCH 02/16] Add ignore feature to help section Fixes #7572 --- app/assets/templates/faq_posts_and_posting_tpl.jst.hbs | 10 ++++++++++ app/assets/templates/help_tpl.jst.hbs | 2 +- config/locales/diaspora/en.yml | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/assets/templates/faq_posts_and_posting_tpl.jst.hbs b/app/assets/templates/faq_posts_and_posting_tpl.jst.hbs index 6fd047cc4..b2ef4b382 100644 --- a/app/assets/templates/faq_posts_and_posting_tpl.jst.hbs +++ b/app/assets/templates/faq_posts_and_posting_tpl.jst.hbs @@ -24,6 +24,16 @@
{{ post_notification_a }}
+
+ +

{{ ignore_user_q }}

+
+
+

{{ ignore_user_a1 }}

+

{{ ignore_user_a2 }}

+

{{ ignore_user_a3 }}

+
+

{{ post_report_q }}

diff --git a/app/assets/templates/help_tpl.jst.hbs b/app/assets/templates/help_tpl.jst.hbs index 7281a958d..b1cd4408e 100644 --- a/app/assets/templates/help_tpl.jst.hbs +++ b/app/assets/templates/help_tpl.jst.hbs @@ -29,7 +29,7 @@ {{ title_pods }}
  • - {{ title_posts_and_posting }} + {{ title_posts_and_posting }} {{ title_posts_and_posting }}
  • diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index cb98753f8..ee54202c4 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -402,6 +402,10 @@ en: hide_posts_a: "If you point your mouse at the top of a post, an X appears on the right. Click it to hide the post and mute notifications about it. You can still see the post if you visit the profile page of the person who posted it." post_notification_q: "How do I get notifications, or stop getting notifications, about a post?" post_notification_a: "You will find a bell icon next to the X at the top right of a post. Click this to enable or disable notifications for that post." + ignore_user_q: "How do I stop someone’s posts from appearing in my stream?" + ignore_user_a1: "If you are currently sharing with that person, removing them from your aspects will stop many of their posts from appearing in your stream. A more complete method is to “ignore” that account. This will prevent any of their posts from appearing in your stream, and they will no longer be able to like or comment on your posts. They will, however, still be able to reshare your posts, comment on reshares of your posts, and their comments on posts by other people which appear in your stream will still be visible to you." + ignore_user_a2: "To ignore an account, click the “ignore” icon (a circle with a diagonal line through it) at the top right of one of their posts. Their posts will instantly disappear from your stream. Alternatively, go to their profile page and click the ignore icon there. You will still be able to see their posts on their profile page, or by using the single-post view." + ignore_user_a3: "A list of people you are ignoring can be found in your account settings under Privacy. To stop ignoring someone, remove them from the list on that page." post_report_q: "How do I report an offensive post?" post_report_a: "Click the alert triangle icon at the top right of the post to report it to your podmin. Enter a reason for reporting this post in the dialog box. Please only report posts that break our %{community_guidelines} or your pod’s terms of service, for example posts containing illegal content, or which are abusive or spam." character_limit_q: "What is the character limit for posts?" From e7cac2e4667ab6786fd67a8317c3ce78d7758ed4 Mon Sep 17 00:00:00 2001 From: goobertron Date: Tue, 22 Aug 2017 19:11:38 +0100 Subject: [PATCH 03/16] Replace with in translations closes #7585 --- Changelog.md | 1 + config/locales/diaspora/en.yml | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index b3dd6ac19..be70379ec 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ ## Features * Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530) * Show users vote in polls [#7550](https://github.com/diaspora/diaspora/pull/7550) +* Add explanation of ignore function to in-app help section [#7585](https://github.com/diaspora/diaspora/pull/7585) # 0.7.0.0 diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index ee54202c4..f22bafc47 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -944,9 +944,9 @@ en: report: title: "Reports overview" - post_label: "Post: %{content}" - comment_label: "Comment: %{data}" - reported_label: "Reported by %{person}" + post_label: "Post: %{content}" + comment_label: "Comment: %{data}" + reported_label: "Reported by %{person}" reason_label: "Reason:" review_link: "Mark as reviewed" delete_link: "Delete item" From 634c13f967a329b3a186a14dee5c4983455e5cdf Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 27 Aug 2017 17:45:24 +0200 Subject: [PATCH 04/16] Remove wrong `format: :json` from status_messages_controller_spec This was added by accident with the rails5 upgrade --- spec/controllers/status_messages_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 8b99c04c2..9ae3a76d2 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -93,7 +93,7 @@ describe StatusMessagesController, :type => :controller do post :create, params: status_message_hash, format: :json expect(response.status).to eq(201) status_message = StatusMessage.find_by_text(text) - expect(status_message.aspect_visibilities.map(&:aspect)).to eq([@aspect1]), format: :json + expect(status_message.aspect_visibilities.map(&:aspect)).to eq([@aspect1]) end it "takes one aspect as string in aspect_ids" do From 6d7ba96c4f403cef61f8ca8bbb81c09e8819d179 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 27 Aug 2017 17:46:43 +0200 Subject: [PATCH 05/16] Remove locals option from render_template assertion The locals option is only supported in ActionView::TestCase, so it is ignored anyway (even worse, it disabled the complete assertion). I added some more assertions to ensure the template is rendered with the correct conversation. closes #7588 --- spec/controllers/conversations_controller_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index dd6b64677..49def945c 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -483,7 +483,9 @@ describe ConversationsController, :type => :controller do it "returns html of conversation" do get :raw, params: {conversation_id: conversation.id} - expect(response).to render_template(partial: "show", locals: {conversation: conversation}) + expect(response).to render_template(partial: "conversations/_show") + expect(response.body).to include conversation.subject + expect(response.body).to include conversation.messages.first.text end it "returns 404 when requesting non-existant conversation" do From cd09c75c50d6b4b344df80a5f44f3f69ef316346 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Aug 2017 20:34:03 +0200 Subject: [PATCH 06/16] Prevent users from zooming in IE Mobile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #7499 According to https://msdn.microsoft.com/en-us/library/dn629259(v=vs.85).aspx, “the minimum-scale, maximum-scale, and initial-scale properties are currently unsupported for Internet Explorer for Windows Phone“. For further information on the viewport properties see https://drafts.csswg.org/css-device-adapt/#viewport-meta closes #7589 --- Changelog.md | 1 + app/views/layouts/application.mobile.haml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index be70379ec..bb96678d0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ * Fix displaying polls with long answers [#7579](https://github.com/diaspora/diaspora/pull/7579) * Fix S3 support [#7566](https://github.com/diaspora/diaspora/pull/7566) * Fix mixed username and timestamp with LTR/RTL scripts [#7575](https://github.com/diaspora/diaspora/pull/7575) +* Prevent users from zooming in IE Mobile [#7589](https://github.com/diaspora/diaspora/pull/7589) ## Features * Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530) diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index 40ca264a4..233122575 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -12,7 +12,7 @@ = render "head" = include_color_theme "mobile" - %meta{name: "viewport", content: "width=device-width, minimum-scale=1 maximum-scale=1"}/ + %meta{name: "viewport", content: "width=device-width, minimum-scale=1, maximum-scale=1, user-scalable=no"}/ %meta{name: "HandheldFriendly", content: "True"}/ %meta{name: "MobileOptimized", content: "320"}/ %meta{"http-equiv" => "cleartype", :content => "on"}/ From 163ffdb19b134d54d446ec0a255994b9cf0f628b Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 27 Aug 2017 20:41:56 +0200 Subject: [PATCH 07/16] Allow multiple reshares without root Follow-up for #7578 Fixes #7587 --- app/models/reshare.rb | 2 +- spec/models/reshare_spec.rb | 42 ++++++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/models/reshare.rb b/app/models/reshare.rb index bc6d8bfa1..118fca68f 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -6,7 +6,7 @@ class Reshare < Post belongs_to :root, class_name: "Post", foreign_key: :root_guid, primary_key: :guid, optional: true validate :root_must_be_public validates_presence_of :root, :on => :create - validates_uniqueness_of :root_guid, :scope => :author_id + validates :root_guid, uniqueness: {scope: :author_id}, allow_nil: true delegate :author, to: :root, prefix: true before_validation do diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index b861065ea..26b0ca267 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -3,15 +3,41 @@ describe Reshare, type: :model do expect(FactoryGirl.build(:reshare)).to be_valid end - it "requires root" do - reshare = FactoryGirl.build(:reshare, root: nil) - expect(reshare).not_to be_valid - end + context "validation" do + it "requires root" do + reshare = FactoryGirl.build(:reshare, root: nil) + expect(reshare).not_to be_valid + end - it "require public root" do - reshare = FactoryGirl.build(:reshare, root: FactoryGirl.create(:status_message, public: false)) - expect(reshare).not_to be_valid - expect(reshare.errors[:base]).to include("Only posts which are public may be reshared.") + it "require public root" do + reshare = FactoryGirl.build(:reshare, root: FactoryGirl.create(:status_message, public: false)) + expect(reshare).not_to be_valid + expect(reshare.errors[:base]).to include("Only posts which are public may be reshared.") + end + + it "allows two reshares without a root" do + reshare1 = FactoryGirl.create(:reshare, author: alice.person) + reshare2 = FactoryGirl.create(:reshare, author: alice.person) + + reshare1.update_attributes(root_guid: nil) + + reshare2.root_guid = nil + expect(reshare2).to be_valid + end + + it "doesn't allow to reshare the same post twice" do + post = FactoryGirl.create(:status_message, public: true) + FactoryGirl.create(:reshare, author: alice.person, root: post) + + expect(FactoryGirl.build(:reshare, author: alice.person, root: post)).not_to be_valid + end + + it "allows to reshare the same post with different people" do + post = FactoryGirl.create(:status_message, public: true) + FactoryGirl.create(:reshare, author: alice.person, root: post) + + expect(FactoryGirl.build(:reshare, author: bob.person, root: post)).to be_valid + end end it "forces public" do From 04035c3eb7e8f85ce5ebbf6b34fd9a4cb57b527a Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 27 Aug 2017 20:48:12 +0200 Subject: [PATCH 08/16] Allow to receive reshares without root closes #7590 --- app/models/reshare.rb | 2 +- spec/models/reshare_spec.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 118fca68f..eda417410 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -5,7 +5,7 @@ class Reshare < Post belongs_to :root, class_name: "Post", foreign_key: :root_guid, primary_key: :guid, optional: true validate :root_must_be_public - validates_presence_of :root, :on => :create + validates :root, presence: true, on: :create, if: proc {|reshare| reshare.author.local? } validates :root_guid, uniqueness: {scope: :author_id}, allow_nil: true delegate :author, to: :root, prefix: true diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index 26b0ca267..de2f652ce 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -4,11 +4,16 @@ describe Reshare, type: :model do end context "validation" do - it "requires root" do - reshare = FactoryGirl.build(:reshare, root: nil) + it "requires root when the author is local" do + reshare = FactoryGirl.build(:reshare, root: nil, author: alice.person) expect(reshare).not_to be_valid end + it "doesn't require root when the author is remote" do + reshare = FactoryGirl.build(:reshare, root: nil, author: remote_raphael) + expect(reshare).to be_valid + end + it "require public root" do reshare = FactoryGirl.build(:reshare, root: FactoryGirl.create(:status_message, public: false)) expect(reshare).not_to be_valid From 2bb7d4e0673675f65ecb9de81eccb76d7861c10d Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Aug 2017 20:55:10 +0200 Subject: [PATCH 09/16] Use language- prefix for codeblocks as defined in the CommonMark spec --- app/assets/javascripts/app/helpers/text_formatter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index b8f46f7ef..8b104db09 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -8,8 +8,7 @@ breaks: true, html: true, linkify: true, - typographer: true, - langPrefix: "" + typographer: true }); var inlinePlugin = window.markdownitForInline; From 98cccda6eaa1e5c5204f301b656c422c456a95a4 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Aug 2017 20:59:02 +0200 Subject: [PATCH 10/16] Remove auto detection of languages with highlightjs Fixes #7476 closes #7591 --- Changelog.md | 1 + app/assets/javascripts/app/helpers/text_formatter.js | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index bb96678d0..985e18f0c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,7 @@ * Remove tiff support from photos [#7576](https://github.com/diaspora/diaspora/pull/7576) * Remove reference from reshares when original post is deleted [#7578](https://github.com/diaspora/diaspora/pull/7578) * Merge migrations from before 0.6.0.0 to CreateSchema [#7580](https://github.com/diaspora/diaspora/pull/7580) +* Remove auto detection of languages with highlightjs [#7591](https://github.com/diaspora/diaspora/pull/7591) ## Bug fixes * Fix displaying polls with long answers [#7579](https://github.com/diaspora/diaspora/pull/7579) diff --git a/app/assets/javascripts/app/helpers/text_formatter.js b/app/assets/javascripts/app/helpers/text_formatter.js index 8b104db09..3fc051404 100644 --- a/app/assets/javascripts/app/helpers/text_formatter.js +++ b/app/assets/javascripts/app/helpers/text_formatter.js @@ -71,10 +71,6 @@ } catch (__) {} } - try { - return hljs.highlightAuto(str).value; - } catch (__) {} - return ""; } }); From a358bf7b664ae25eae163641460f1c0795e3001b Mon Sep 17 00:00:00 2001 From: flaburgan Date: Sun, 27 Aug 2017 21:15:49 +0200 Subject: [PATCH 11/16] Move the notification to be the first icon on the left closes #7592 --- Changelog.md | 1 + app/assets/templates/post-controls_tpl.jst.hbs | 12 ++++++------ .../single-post-moderation_tpl.jst.hbs | 12 ++++++------ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Changelog.md b/Changelog.md index 985e18f0c..315cc0976 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ * Remove reference from reshares when original post is deleted [#7578](https://github.com/diaspora/diaspora/pull/7578) * Merge migrations from before 0.6.0.0 to CreateSchema [#7580](https://github.com/diaspora/diaspora/pull/7580) * Remove auto detection of languages with highlightjs [#7591](https://github.com/diaspora/diaspora/pull/7591) +* Move enable/disable notification icon [#7592](https://github.com/diaspora/diaspora/pull/7592) ## Bug fixes * Fix displaying polls with long answers [#7579](https://github.com/diaspora/diaspora/pull/7579) diff --git a/app/assets/templates/post-controls_tpl.jst.hbs b/app/assets/templates/post-controls_tpl.jst.hbs index 560f366f4..4e6238391 100644 --- a/app/assets/templates/post-controls_tpl.jst.hbs +++ b/app/assets/templates/post-controls_tpl.jst.hbs @@ -3,12 +3,6 @@ {{else}} - - - - - - {{#if participation}} @@ -18,6 +12,12 @@ {{/if}} + + + + + + diff --git a/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs index d81f6a14b..f58389501 100644 --- a/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs +++ b/app/assets/templates/single-post-viewer/single-post-moderation_tpl.jst.hbs @@ -5,12 +5,6 @@ {{else}} - - - - - - {{#if participation}} @@ -20,6 +14,12 @@ {{/if}} + + + + + + From 9d2763089d2796deb5a5d2388f0a92d13447761b Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Aug 2017 21:42:48 +0200 Subject: [PATCH 12/16] Replace where...first with find_by Fixes #7539 closes #7593 --- app/models/comment.rb | 2 +- app/models/conversation.rb | 10 +++++----- app/models/like.rb | 2 +- app/models/message.rb | 8 ++++---- app/models/person.rb | 2 +- app/models/post.rb | 4 ++-- app/models/service.rb | 2 +- app/models/user.rb | 6 +++--- app/models/user/querying.rb | 4 ++-- app/models/user/social_actions.rb | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 4b6baa250..45603e420 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -45,7 +45,7 @@ class Comment < ApplicationRecord after_destroy do self.parent.update_comments_counter - participation = author.participations.where(target_id: post.id).first + participation = author.participations.find_by(target_id: post.id) participation.unparticipate! if participation.present? end diff --git a/app/models/conversation.rb b/app/models/conversation.rb index f597af001..43f37f4c1 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -38,10 +38,10 @@ class Conversation < ApplicationRecord end def set_read(user) - if visibility = self.conversation_visibilities.where(:person_id => user.person.id).first - visibility.unread = 0 - visibility.save - end + visibility = conversation_visibilities.find_by(person_id: user.person.id) + return unless visibility + visibility.unread = 0 + visibility.save end def participant_handles @@ -57,7 +57,7 @@ class Conversation < ApplicationRecord def last_author return unless @last_author.present? || messages.size > 0 @last_author_id ||= messages.pluck(:author_id).last - @last_author ||= Person.includes(:profile).where(id: @last_author_id).first + @last_author ||= Person.includes(:profile).find_by(id: @last_author_id) end def ordered_participants diff --git a/app/models/like.rb b/app/models/like.rb index 828d5b8aa..09776aa8b 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -30,7 +30,7 @@ class Like < ApplicationRecord after_destroy do self.parent.update_likes_counter - participation = author.participations.where(target_id: target.id).first + participation = author.participations.find_by(target_id: target.id) participation.unparticipate! if participation.present? end diff --git a/app/models/message.rb b/app/models/message.rb index 95992e689..07e952fff 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -15,10 +15,10 @@ class Message < ApplicationRecord end def increase_unread(user) - if vis = ConversationVisibility.where(:conversation_id => self.conversation_id, :person_id => user.person.id).first - vis.unread += 1 - vis.save - end + vis = ConversationVisibility.find_by(conversation_id: conversation_id, person_id: user.person.id) + return unless vis + vis.unread += 1 + vis.save end def message diff --git a/app/models/person.rb b/app/models/person.rb index 87a0f02cf..ca7210d52 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -191,7 +191,7 @@ class Person < ApplicationRecord def self.find_from_guid_or_username(params) p = if params[:id].present? - Person.where(:guid => params[:id]).first + Person.find_by(guid: params[:id]) elsif params[:username].present? && u = User.find_by_username(params[:username]) u.person else diff --git a/app/models/post.rb b/app/models/post.rb index e592400f6..53157702f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -124,12 +124,12 @@ class Post < ApplicationRecord def reshare_for(user) return unless user - reshares.where(:author_id => user.person.id).first + reshares.find_by(author_id: user.person.id) end def like_for(user) return unless user - likes.where(:author_id => user.person.id).first + likes.find_by(author_id: user.person.id) end ############# diff --git a/app/models/service.rb b/app/models/service.rb index 890fc02bc..835e92e4c 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -24,7 +24,7 @@ class Service < ApplicationRecord def first_from_omniauth( auth_hash ) @@auth = auth_hash - where( type: service_type, uid: options[:uid] ).first + find_by(type: service_type, uid: options[:uid]) end def initialize_from_omniauth( auth_hash ) diff --git a/app/models/user.rb b/app/models/user.rb index d596dd9d4..f57c1626a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -176,7 +176,7 @@ class User < ApplicationRecord if pref_hash[key] == 'true' self.user_preferences.find_or_create_by(email_type: key) else - block = self.user_preferences.where(:email_type => key).first + block = user_preferences.find_by(email_type: key) if block block.destroy end @@ -289,9 +289,9 @@ class User < ApplicationRecord # @return [Like] def like_for(target) if target.likes.loaded? - return target.likes.detect{ |like| like.author_id == self.person.id } + target.likes.find {|like| like.author_id == person.id } else - return Like.where(:author_id => self.person.id, :target_type => target.class.base_class.to_s, :target_id => target.id).first + Like.find_by(author_id: person.id, target_type: target.class.base_class.to_s, target_id: target.id) end end diff --git a/app/models/user/querying.rb b/app/models/user/querying.rb index f9ff0f001..11a3e186c 100644 --- a/app/models/user/querying.rb +++ b/app/models/user/querying.rb @@ -28,7 +28,7 @@ module User::Querying def block_for(person) return nil unless person - self.blocks.where(person_id: person.id).first + blocks.find_by(person_id: person.id) end def aspects_with_shareable(base_class_name_or_class, shareable_id) @@ -38,7 +38,7 @@ module User::Querying end def contact_for_person_id(person_id) - Contact.where(:user_id => self.id, :person_id => person_id).includes(:person => :profile).first + Contact.includes(person: :profile).find_by(user_id: id, person_id: person_id) end # @param [Person] person diff --git a/app/models/user/social_actions.rb b/app/models/user/social_actions.rb index a01789a3c..d110a81c7 100644 --- a/app/models/user/social_actions.rb +++ b/app/models/user/social_actions.rb @@ -49,7 +49,7 @@ module User::SocialActions def update_or_create_participation!(target) return if target.author == person - participation = participations.where(target_id: target).first + participation = participations.find_by(target_id: target) if participation.present? participation.update!(count: participation.count.next) else From 666ada44f117f1a956694756b1adeed96208aa6e Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Sun, 27 Aug 2017 22:21:19 +0200 Subject: [PATCH 13/16] Fix conversation recipient prefill on profile page Fixes #7586 Use the already available data about the recipient for the prefill --- .../app/views/profile_header_view.js | 9 ++++++-- app/controllers/conversations_controller.rb | 4 +--- .../conversations_controller_spec.rb | 5 ----- .../app/views/profile_header_view_spec.js | 21 ++++++++++--------- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/app/views/profile_header_view.js b/app/assets/javascripts/app/views/profile_header_view.js index 1fb6e0e1d..49fecd656 100644 --- a/app/assets/javascripts/app/views/profile_header_view.js +++ b/app/assets/javascripts/app/views/profile_header_view.js @@ -81,8 +81,13 @@ app.views.ProfileHeader = app.views.Base.extend({ showMessageModal: function(){ $("#conversationModal").on("modal:loaded", function() { - new app.views.ConversationsForm({prefill: gon.conversationPrefill}); - }); + new app.views.ConversationsForm({ + prefill: [_.extend({ + avatar: this.model.get("profile").avatar.small, + handle: this.model.get("diaspora_id") + }, this.model.attributes)] + }); + }.bind(this)); app.helpers.showModal("#conversationModal"); } }); diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index 3f1977655..87cb28ded 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -103,9 +103,7 @@ class ConversationsController < ApplicationController render :layout => true else - if params[:contact_id] - gon.push conversation_prefill: [current_user.contacts.find(params[:contact_id]).person.as_json] - elsif params[:aspect_id] + if params[:aspect_id] gon.push conversation_prefill: current_user.aspects .find(params[:aspect_id]).contacts.map {|c| c.person.as_json } end diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 49def945c..1d4206722 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -21,11 +21,6 @@ describe ConversationsController, :type => :controller do expect(response).to be_success end - it "assigns a contact if passed a contact id" do - get :new, params: {contact_id: alice.contacts.first.id, modal: true} - expect(controller.gon.conversation_prefill).to eq([alice.contacts.first.person.as_json]) - end - it "assigns a set of contacts if passed an aspect id" do get :new, params: {aspect_id: alice.aspects.first.id, modal: true} expect(controller.gon.conversation_prefill).to eq(alice.aspects.first.contacts.map {|c| c.person.as_json }) diff --git a/spec/javascripts/app/views/profile_header_view_spec.js b/spec/javascripts/app/views/profile_header_view_spec.js index 999d56cd6..3488d8446 100644 --- a/spec/javascripts/app/views/profile_header_view_spec.js +++ b/spec/javascripts/app/views/profile_header_view_spec.js @@ -4,8 +4,11 @@ describe("app.views.ProfileHeader", function() { this.model = factory.personWithProfile({ diaspora_id: "my@pod", name: "User Name", - relationship: 'mutual', - profile: { tags: ['test'] } + relationship: "mutual", + profile: { + avatar: {small: "http://example.org/avatar.jpg"}, + tags: ["test"] + } }); this.view = new app.views.ProfileHeader({model: this.model}); loginAs(factory.userAttrs()); @@ -71,17 +74,15 @@ describe("app.views.ProfileHeader", function() { }); it("initializes app.views.ConversationsForm with correct parameters when modal is loaded", function() { - gon.conversationPrefill = [ - {id: 1, name: "diaspora user", handle: "diaspora-user@pod.tld"}, - {id: 2, name: "other diaspora user", handle: "other-diaspora-user@pod.tld"}, - {id: 3, name: "user@pod.tld", handle: "user@pod.tld"} - ]; - spyOn(app.views.ConversationsForm.prototype, "initialize"); spyOn($.fn, "load").and.callFake(function(url, callback) { callback(); }); this.view.showMessageModal(); - expect(app.views.ConversationsForm.prototype.initialize) - .toHaveBeenCalledWith({prefill: gon.conversationPrefill}); + expect(app.views.ConversationsForm.prototype.initialize).toHaveBeenCalled(); + var prefill = app.views.ConversationsForm.prototype.initialize.calls.mostRecent().args[0].prefill; + expect(prefill.length).toBe(1); + expect(prefill[0].handle).toBe("my@pod"); + expect(prefill[0].name).toBe("User Name"); + expect(prefill[0].avatar).toBe("http://example.org/avatar.jpg"); }); }); }); From 48630b3a04707394f26a305ae2f212b44d6867bb Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Mon, 28 Aug 2017 00:23:39 +0200 Subject: [PATCH 14/16] Fix conversation recipient prefill on contacts page Use the already available contacts data for the prefill --- app/assets/javascripts/app/pages/contacts.js | 10 +++++++++- app/controllers/conversations_controller.rb | 4 ---- app/views/conversations/new.html.haml | 3 +-- .../conversations_controller_spec.rb | 5 ----- spec/javascripts/app/pages/contacts_spec.js | 19 +++++++++++-------- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/assets/javascripts/app/pages/contacts.js b/app/assets/javascripts/app/pages/contacts.js index f9bd2db27..64c17422d 100644 --- a/app/assets/javascripts/app/pages/contacts.js +++ b/app/assets/javascripts/app/pages/contacts.js @@ -80,7 +80,15 @@ app.pages.Contacts = Backbone.View.extend({ showMessageModal: function(){ $("#conversationModal").on("modal:loaded", function() { - new app.views.ConversationsForm({prefill: gon.conversationPrefill}); + var people = app.contacts.filter(function(contact) { + return contact.inAspect(app.aspect.get("id")); + }).map(function(contact) { + return _.extend({ + avatar: contact.person.get("profile").avatar.small, + handle: contact.person.get("diaspora_id") + }, contact.person.attributes); + }); + new app.views.ConversationsForm({prefill: people}); }); app.helpers.showModal("#conversationModal"); }, diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index 87cb28ded..7694cef79 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -103,10 +103,6 @@ class ConversationsController < ApplicationController render :layout => true else - if params[:aspect_id] - gon.push conversation_prefill: current_user.aspects - .find(params[:aspect_id]).contacts.map {|c| c.person.as_json } - end render :layout => false end end diff --git a/app/views/conversations/new.html.haml b/app/views/conversations/new.html.haml index e66a929dd..e43e714c4 100644 --- a/app/views/conversations/new.html.haml +++ b/app/views/conversations/new.html.haml @@ -1,2 +1 @@ -= include_gon camel_case: true -= render 'conversations/new' += render "conversations/new" diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 1d4206722..a2d2e1d49 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -20,11 +20,6 @@ describe ConversationsController, :type => :controller do get :new, params: {modal: true} expect(response).to be_success end - - it "assigns a set of contacts if passed an aspect id" do - get :new, params: {aspect_id: alice.aspects.first.id, modal: true} - expect(controller.gon.conversation_prefill).to eq(alice.aspects.first.contacts.map {|c| c.person.as_json }) - end end context "mobile" do diff --git a/spec/javascripts/app/pages/contacts_spec.js b/spec/javascripts/app/pages/contacts_spec.js index a1be4be48..8ac9c19bb 100644 --- a/spec/javascripts/app/pages/contacts_spec.js +++ b/spec/javascripts/app/pages/contacts_spec.js @@ -290,17 +290,20 @@ describe("app.pages.Contacts", function(){ }); it("initializes app.views.ConversationsForm with correct parameters when modal is loaded", function() { - gon.conversationPrefill = [ - {id: 1, name: "diaspora user", handle: "diaspora-user@pod.tld"}, - {id: 2, name: "other diaspora user", handle: "other-diaspora-user@pod.tld"}, - {id: 3, name: "user@pod.tld", handle: "user@pod.tld"} - ]; - spyOn(app.views.ConversationsForm.prototype, "initialize"); + app.aspect = new app.models.Aspect(app.contacts.first().get("aspect_memberships")[0].aspect); this.view.showMessageModal(); $("#conversationModal").trigger("modal:loaded"); - expect(app.views.ConversationsForm.prototype.initialize) - .toHaveBeenCalledWith({prefill: gon.conversationPrefill}); + expect(app.views.ConversationsForm.prototype.initialize).toHaveBeenCalled(); + + var prefill = app.views.ConversationsForm.prototype.initialize.calls.mostRecent().args[0].prefill; + var people = app.contacts.filter(function(contact) { return contact.inAspect(app.aspect.get("id")); }); + expect(prefill.length).toBe(people.length); + + var person = app.contacts.first().person; + expect(prefill[0].handle).toBe(person.get("diaspora_id")); + expect(prefill[0].name).toBe(person.get("name")); + expect(prefill[0].avatar).toBe(person.get("profile").avatar.small); }); }); }); From 02d9d350d9ea664e96059029ad6912adee19f37e Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Mon, 28 Aug 2017 01:31:59 +0200 Subject: [PATCH 15/16] Move person extension for prefills to conversations form view closes #7599 --- Changelog.md | 1 + app/assets/javascripts/app/pages/contacts.js | 9 ++------- .../app/views/conversations_form_view.js | 9 +++++++-- .../javascripts/app/views/profile_header_view.js | 7 +------ spec/javascripts/app/pages/contacts_spec.js | 9 ++------- .../app/views/conversations_form_view_spec.js | 15 +++++++++++++-- .../app/views/profile_header_view_spec.js | 9 +++------ spec/javascripts/jasmine_helpers/factory.js | 8 +++++--- 8 files changed, 34 insertions(+), 33 deletions(-) diff --git a/Changelog.md b/Changelog.md index 315cc0976..5adc427e2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ * Fix S3 support [#7566](https://github.com/diaspora/diaspora/pull/7566) * Fix mixed username and timestamp with LTR/RTL scripts [#7575](https://github.com/diaspora/diaspora/pull/7575) * Prevent users from zooming in IE Mobile [#7589](https://github.com/diaspora/diaspora/pull/7589) +* Fix recipient prefill on contacts and profile page [#7599](https://github.com/diaspora/diaspora/pull/7599) ## Features * Ask for confirmation when leaving a submittable comment field [#7530](https://github.com/diaspora/diaspora/pull/7530) diff --git a/app/assets/javascripts/app/pages/contacts.js b/app/assets/javascripts/app/pages/contacts.js index 64c17422d..a7d21a0b0 100644 --- a/app/assets/javascripts/app/pages/contacts.js +++ b/app/assets/javascripts/app/pages/contacts.js @@ -80,14 +80,9 @@ app.pages.Contacts = Backbone.View.extend({ showMessageModal: function(){ $("#conversationModal").on("modal:loaded", function() { - var people = app.contacts.filter(function(contact) { + var people = _.pluck(app.contacts.filter(function(contact) { return contact.inAspect(app.aspect.get("id")); - }).map(function(contact) { - return _.extend({ - avatar: contact.person.get("profile").avatar.small, - handle: contact.person.get("diaspora_id") - }, contact.person.attributes); - }); + }), "person"); new app.views.ConversationsForm({prefill: people}); }); app.helpers.showModal("#conversationModal"); diff --git a/app/assets/javascripts/app/views/conversations_form_view.js b/app/assets/javascripts/app/views/conversations_form_view.js index a28b6d426..a360f0917 100644 --- a/app/assets/javascripts/app/views/conversations_form_view.js +++ b/app/assets/javascripts/app/views/conversations_form_view.js @@ -52,8 +52,13 @@ app.views.ConversationsForm = app.views.Base.extend({ this.setupAvatarFallback(personEl); }, - prefill: function(handles) { - handles.forEach(this.addRecipient.bind(this)); + prefill: function(people) { + people.forEach(function(person) { + this.addRecipient(_.extend({ + avatar: person.get("profile").avatar.small, + handle: person.get("diaspora_id") + }, person.attributes)); + }, this); }, updateContactIdsListInput: function() { diff --git a/app/assets/javascripts/app/views/profile_header_view.js b/app/assets/javascripts/app/views/profile_header_view.js index 49fecd656..14247369a 100644 --- a/app/assets/javascripts/app/views/profile_header_view.js +++ b/app/assets/javascripts/app/views/profile_header_view.js @@ -81,12 +81,7 @@ app.views.ProfileHeader = app.views.Base.extend({ showMessageModal: function(){ $("#conversationModal").on("modal:loaded", function() { - new app.views.ConversationsForm({ - prefill: [_.extend({ - avatar: this.model.get("profile").avatar.small, - handle: this.model.get("diaspora_id") - }, this.model.attributes)] - }); + new app.views.ConversationsForm({prefill: [this.model]}); }.bind(this)); app.helpers.showModal("#conversationModal"); } diff --git a/spec/javascripts/app/pages/contacts_spec.js b/spec/javascripts/app/pages/contacts_spec.js index 8ac9c19bb..fa9f001d2 100644 --- a/spec/javascripts/app/pages/contacts_spec.js +++ b/spec/javascripts/app/pages/contacts_spec.js @@ -297,13 +297,8 @@ describe("app.pages.Contacts", function(){ expect(app.views.ConversationsForm.prototype.initialize).toHaveBeenCalled(); var prefill = app.views.ConversationsForm.prototype.initialize.calls.mostRecent().args[0].prefill; - var people = app.contacts.filter(function(contact) { return contact.inAspect(app.aspect.get("id")); }); - expect(prefill.length).toBe(people.length); - - var person = app.contacts.first().person; - expect(prefill[0].handle).toBe(person.get("diaspora_id")); - expect(prefill[0].name).toBe(person.get("name")); - expect(prefill[0].avatar).toBe(person.get("profile").avatar.small); + var contacts = app.contacts.filter(function(contact) { return contact.inAspect(app.aspect.get("id")); }); + expect(_.pluck(prefill, "id")).toEqual(contacts.map(function(contact) { return contact.person.id; })); }); }); }); diff --git a/spec/javascripts/app/views/conversations_form_view_spec.js b/spec/javascripts/app/views/conversations_form_view_spec.js index b0d065350..419af34c5 100644 --- a/spec/javascripts/app/views/conversations_form_view_spec.js +++ b/spec/javascripts/app/views/conversations_form_view_spec.js @@ -85,7 +85,11 @@ describe("app.views.ConversationsForm", function() { describe("prefill", function() { beforeEach(function() { - this.prefills = [{name: "diaspora user"}, {name: "other diaspora user"}, {name: "user"}]; + this.prefills = [ + factory.personWithProfile({"diaspora_id": "alice@pod.tld"}), + factory.personWithProfile({"diaspora_id": "bob@pod.tld"}), + factory.personWithProfile({"diaspora_id": "carol@pod.tld"}) + ]; }); it("calls addRecipient for each prefilled participant", function() { @@ -95,7 +99,14 @@ describe("app.views.ConversationsForm", function() { var allArgsFlattened = app.views.ConversationsForm.prototype.addRecipient.calls.allArgs().map(function(arg) { return arg[0]; }); - expect(allArgsFlattened).toEqual(this.prefills); + + expect(_.pluck(allArgsFlattened, "handle")).toEqual( + this.prefills.map(function(person) { return person.get("diaspora_id"); }) + ); + + expect(_.pluck(allArgsFlattened, "avatar")).toEqual( + this.prefills.map(function(person) { return person.get("profile").avatar.small; }) + ); }); }); diff --git a/spec/javascripts/app/views/profile_header_view_spec.js b/spec/javascripts/app/views/profile_header_view_spec.js index 3488d8446..3b5d086a9 100644 --- a/spec/javascripts/app/views/profile_header_view_spec.js +++ b/spec/javascripts/app/views/profile_header_view_spec.js @@ -77,12 +77,9 @@ describe("app.views.ProfileHeader", function() { spyOn(app.views.ConversationsForm.prototype, "initialize"); spyOn($.fn, "load").and.callFake(function(url, callback) { callback(); }); this.view.showMessageModal(); - expect(app.views.ConversationsForm.prototype.initialize).toHaveBeenCalled(); - var prefill = app.views.ConversationsForm.prototype.initialize.calls.mostRecent().args[0].prefill; - expect(prefill.length).toBe(1); - expect(prefill[0].handle).toBe("my@pod"); - expect(prefill[0].name).toBe("User Name"); - expect(prefill[0].avatar).toBe("http://example.org/avatar.jpg"); + expect(app.views.ConversationsForm.prototype.initialize).toHaveBeenCalledWith({ + prefill: [this.model] + }); }); }); }); diff --git a/spec/javascripts/jasmine_helpers/factory.js b/spec/javascripts/jasmine_helpers/factory.js index 217c68952..9b0d4ecfc 100644 --- a/spec/javascripts/jasmine_helpers/factory.js +++ b/spec/javascripts/jasmine_helpers/factory.js @@ -138,9 +138,11 @@ var factory = { "full_name": "bob grimm", "gender": "robot", "id": id, - "image_url": "http://localhost:3000/assets/user/default.png", - "image_url_medium": "http://localhost:3000/assets/user/default.png", - "image_url_small": "http://localhost:3000/assets/user/default.png", + "avatar": { + "small": "http://localhost:3000/assets/user/default.png", + "medium": "http://localhost:3000/assets/user/default.png", + "large": "http://localhost:3000/assets/user/default.png" + }, "last_name": "Grimm", "location": "Earth", "nsfw": false, From d130697ce2578fd119bdeeabc8f4b9abc39a1db2 Mon Sep 17 00:00:00 2001 From: Steffen van Bergerem Date: Mon, 28 Aug 2017 13:44:58 +0200 Subject: [PATCH 16/16] Use Bootstrap 3 progress-bar for polls closes #7600 --- Changelog.md | 1 + app/assets/javascripts/app/views/poll_view.js | 14 +++---- .../_color_theme_override_dark.scss | 4 +- app/assets/stylesheets/poll.scss | 25 ++++------- app/assets/templates/poll_tpl.jst.hbs | 42 ++++++++++--------- features/desktop/post_preview.feature | 2 +- features/desktop/post_with_a_poll.feature | 8 ++-- .../step_definitions/post_with_poll_steps.rb | 4 +- spec/javascripts/app/views/poll_view_spec.js | 12 +++--- 9 files changed, 52 insertions(+), 60 deletions(-) diff --git a/Changelog.md b/Changelog.md index 5adc427e2..96f934f27 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ * Merge migrations from before 0.6.0.0 to CreateSchema [#7580](https://github.com/diaspora/diaspora/pull/7580) * Remove auto detection of languages with highlightjs [#7591](https://github.com/diaspora/diaspora/pull/7591) * Move enable/disable notification icon [#7592](https://github.com/diaspora/diaspora/pull/7592) +* Use Bootstrap 3 progress-bar for polls [#7600](https://github.com/diaspora/diaspora/pull/7600) ## Bug fixes * Fix displaying polls with long answers [#7579](https://github.com/diaspora/diaspora/pull/7579) diff --git a/app/assets/javascripts/app/views/poll_view.js b/app/assets/javascripts/app/views/poll_view.js index 275fb02d6..55710bfba 100644 --- a/app/assets/javascripts/app/views/poll_view.js +++ b/app/assets/javascripts/app/views/poll_view.js @@ -5,7 +5,7 @@ app.views.Poll = app.views.Base.extend({ events: { "click .submit" : "clickSubmit", - "click .toggle_result" : "toggleResult" + "click .toggle-result": "toggleResult" }, initialize: function() { @@ -55,7 +55,7 @@ app.views.Poll = app.views.Base.extend({ percent = Math.round(answer.vote_count / participation_count * 100); } - var progressBar = _this.$(".poll_progress_bar[data-answerid="+answer.id+"]"); + var progressBar = _this.$(".progress-bar[data-answerid=" + answer.id + "]"); _this.setProgressBarData(progressBar, percent); }); @@ -68,8 +68,8 @@ app.views.Poll = app.views.Base.extend({ pollButtons: function() { if(!this.poll || !this.poll.post_id) { - this.$('.submit').attr('disabled', true); - this.$('.toggle_result').attr('disabled', true); + this.$(".submit").attr("disabled", true); + this.$(".toggle-result").attr("disabled", true); } }, @@ -83,14 +83,14 @@ app.views.Poll = app.views.Base.extend({ } this.toggleElements(); - var toggle_result = this.$('.toggle_result'); + var toggleResult = this.$(".toggle-result"); if(!this.toggleMode) { - toggle_result.html(Diaspora.I18n.t("poll.close_result")); + toggleResult.html(Diaspora.I18n.t("poll.close_result")); this.toggleMode = 1; } else { - toggle_result.html(Diaspora.I18n.t("poll.show_result")); + toggleResult.html(Diaspora.I18n.t("poll.show_result")); this.toggleMode = 0; } }, diff --git a/app/assets/stylesheets/color_themes/_color_theme_override_dark.scss b/app/assets/stylesheets/color_themes/_color_theme_override_dark.scss index a09028a3e..90f859910 100644 --- a/app/assets/stylesheets/color_themes/_color_theme_override_dark.scss +++ b/app/assets/stylesheets/color_themes/_color_theme_override_dark.scss @@ -19,9 +19,9 @@ body { .info .tag { background-color: $gray-light; } - .poll_form .progress { + .poll-form .progress { background-color: $gray-dark; - .bar { background-color: $gray-light; } + .progress-bar { background-color: $gray-light; } .users-vote { background-color: $brand-primary; } } diff --git a/app/assets/stylesheets/poll.scss b/app/assets/stylesheets/poll.scss index 5bd220a98..146d4f2fa 100644 --- a/app/assets/stylesheets/poll.scss +++ b/app/assets/stylesheets/poll.scss @@ -1,4 +1,4 @@ -.poll_form { +.poll-form { border-bottom: 1px solid $border-grey; border-top: 1px solid $border-grey; margin: 10px 0; @@ -14,38 +14,27 @@ } .progress { - background-image: none; - box-shadow: 0 0 0; height: 10px; margin-bottom: 5px; clear: both; - .bar { - background: $border-dark-grey none; - color: $text-dark-grey; - height: 100%; - text-align: left; - } - - .users-vote { - background-color: $brand-primary; - } + .progress-bar { background-color: $border-dark-grey; } + .users-vote { background-color: $brand-primary; } } .submit[disabled] { color: $text-grey; cursor: default; - - &:hover, - &:active { - background-image: none; - } } } .poll-content { margin-top: 5px; + .result-head { + margin-bottom: 5px; + } + [type=radio], label { font-weight: normal; diff --git a/app/assets/templates/poll_tpl.jst.hbs b/app/assets/templates/poll_tpl.jst.hbs index 2a8b221c2..707ec7482 100644 --- a/app/assets/templates/poll_tpl.jst.hbs +++ b/app/assets/templates/poll_tpl.jst.hbs @@ -1,8 +1,8 @@ {{#if poll}} -
    -
    +
    +
    {{poll.question}} -
    +
    {{t "poll.count" count=poll.participation_count}}
    @@ -12,24 +12,26 @@ {{/if}} {{#poll.poll_answers}}
    - - {{#if isCurrentUserVote}} - - {{else}} - - {{/if}} -
    - - ({{t "poll.answer_count" count=vote_count}}) -
    -
    +
    + {{#if isCurrentUserVote}} -
    + {{else}} -
    + + {{/if}} +
    + + ({{t "poll.answer_count" count=vote_count}}) +
    +
    +
    + {{#if isCurrentUserVote}} +
    + {{else}} +
    {{/if}}
    @@ -39,7 +41,7 @@ {{#if preview}} {{t "poll.show_result"}} {{else}} - {{t "poll.show_result"}} + {{t "poll.show_result"}} {{/if}}
    diff --git a/features/desktop/post_preview.feature b/features/desktop/post_preview.feature index d2a69b687..3a240e1a0 100644 --- a/features/desktop/post_preview.feature +++ b/features/desktop/post_preview.feature @@ -80,7 +80,7 @@ Feature: preview posts in the stream | normal | | not normal | And I preview the post - Then I should see a ".poll_form" within ".md-preview .stream-element" + Then I should see a ".poll-form" within ".md-preview .stream-element" And I should see a "form" within ".md-preview .stream-element" And I close the publisher diff --git a/features/desktop/post_with_a_poll.feature b/features/desktop/post_with_a_poll.feature index 5a27fc7ee..31843c3eb 100644 --- a/features/desktop/post_with_a_poll.feature +++ b/features/desktop/post_with_a_poll.feature @@ -46,7 +46,7 @@ Feature: posting with a poll | normal | | not normal | And I press "Share" - Then I should see a ".poll_form" within ".stream-element" + Then I should see a ".poll-form" within ".stream-element" And I should see a "form" within ".stream-element" Scenario: vote for an option @@ -62,9 +62,9 @@ Feature: posting with a poll And I check the first option And I press "Vote" within ".stream-element" - Then I should see an element ".poll_progress_bar" + Then I should see an element ".progress-bar" And I should see an element ".percentage" - And I should see "1 vote so far" within ".poll_statistic" + And I should see "1 vote so far" within ".poll-statistic" Scenario: click to show result Given I expand the publisher @@ -76,7 +76,7 @@ Feature: posting with a poll | normal | | not normal | And I press "Share" - And I click on selector ".toggle_result" + And I click on selector ".toggle-result" Then I should see an element ".percentage" Scenario: validate answer input diff --git a/features/step_definitions/post_with_poll_steps.rb b/features/step_definitions/post_with_poll_steps.rb index 4d95ef1db..7e9182841 100644 --- a/features/step_definitions/post_with_poll_steps.rb +++ b/features/step_definitions/post_with_poll_steps.rb @@ -19,8 +19,8 @@ When /^I fill in the following for the options:$/ do |table| end When /^I check the first option$/ do - page.should have_css('.poll_form input') - first(".poll_form input").click + page.should have_css(".poll-form input") + first(".poll-form input").click end When(/^I fill in values for the first two options$/) do diff --git a/spec/javascripts/app/views/poll_view_spec.js b/spec/javascripts/app/views/poll_view_spec.js index 034b0a5eb..03aa2aee7 100644 --- a/spec/javascripts/app/views/poll_view_spec.js +++ b/spec/javascripts/app/views/poll_view_spec.js @@ -8,16 +8,16 @@ describe("app.views.Poll", function(){ describe("setProgressBar", function(){ it("sets the progress bar according to the voting result", function(){ var percentage = (this.view.poll.poll_answers[0].vote_count / this.view.poll.participation_count)*100; - expect(this.view.$('.poll_progress_bar:first').css('width')).toBe(percentage+"%"); + expect(this.view.$(".progress-bar:first").css("width")).toBe(percentage + "%"); expect(this.view.$(".percentage:first").text()).toBe(percentage + "%"); }); }); describe("toggleResult", function(){ it("toggles the progress bar and result", function(){ - expect($(".poll_progress_bar_wrapper:first")).toBeHidden(); + expect($(".progress:first")).toBeHidden(); this.view.toggleResult(); - expect($(".poll_progress_bar_wrapper:first")).toBeVisible(); + expect($(".progress:first")).toBeVisible(); }); }); @@ -39,7 +39,7 @@ describe("app.views.Poll", function(){ var question = ""; this.view.poll.question = question; this.view.render(); - expect(this.view.$('.poll_head strong').text()).toBe(question); + expect(this.view.$(".poll-head strong").text()).toBe(question); }); }); @@ -80,14 +80,14 @@ describe("app.views.Poll", function(){ it("adds 'users-vote' class to progress bar for the option the user voted for", function() { var answer = this.view.poll.poll_answers[0]; this.view.model.set("poll_participation_answer_id", answer.id); - expect(this.view.$(".poll_progress_bar.users-vote").length).toBe(1); + expect(this.view.$(".progress-bar.users-vote").length).toBe(1); }); it("doesn't add 'users-vote' class to progress bar of the options the user didn't vote for", function() { var answer1 = this.view.poll.poll_answers[0]; var answer2 = this.view.poll.poll_answers[1]; this.view.model.set("poll_participation_answer_id", answer1.id); - expect(this.view.$(".poll_progress_bar[data-answerid='" + answer2.id + "']").hasClass("users-vote")).toBe(false); + expect(this.view.$(".progress-bar[data-answerid='" + answer2.id + "']").hasClass("users-vote")).toBe(false); }); it("adds label next to the answer the user voted for", function() {