Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consul pull ⬇️ #886

Merged
merged 32 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4c225aa
Remove document cached_attachment value after destroy_upload action.
Senen Sep 11, 2017
78c231b
Added db/schema after migration
Sep 13, 2017
0b70839
Add base controller for Admin:Poll controller
aitbw Sep 13, 2017
f1eb535
The arrows of the datepicker for changing the month didn't appear. Th…
Sep 14, 2017
a7e570e
Added new line at the end of the file.
Sep 14, 2017
0611e0f
Validate presence of 'poll_id' attribute on Poll::Question model
aitbw Sep 14, 2017
ce61adb
Merge branch 'master' into iagirre-display-datepicker-arrows
bertocq Sep 14, 2017
354d07c
Changes suggested in the PR https://github.com/consul/consul/pull/186…
Sep 15, 2017
5ca4a60
Merge branch 'iagirre-display-datepicker-arrows' of github.com:wairbu…
Sep 15, 2017
d629aef
When "Profiles" submenus are selected, the "Site custom" menu doesn't…
Sep 15, 2017
4bcb9ba
Extra indentation spaces erased.
Sep 15, 2017
b889d23
Fixed width property, changed to top.
Sep 18, 2017
12d34a3
Switch flag/unflag buttons on use via ajax
xarlybovi Sep 18, 2017
15ccef8
Poll::Question model spec refactor to improve DRYness
aitbw Sep 14, 2017
e4abe0d
Merge pull request #1849 from rockandror/documentable-fix
bertocq Sep 19, 2017
5d6c4f0
Merge pull request #1868 from wairbut-m2c/aperez-validate-poll-questi…
bertocq Sep 19, 2017
8cbdc5a
Merge pull request #1874 from wairbut-m2c/iagirre-admin-menu-wrongful…
bertocq Sep 19, 2017
f99612d
Merge pull request #1869 from wairbut-m2c/iagirre-display-datepicker-…
bertocq Sep 19, 2017
37be890
Fixes dev seeds
voodoorai2000 Sep 19, 2017
033df11
Merge pull request #1889 from consul/dev_seeds
bertocq Sep 19, 2017
cf2dff1
Small class names and html refactor
xarlybovi Sep 19, 2017
61c9536
Add flagging/unflagging rspec
xarlybovi Sep 19, 2017
1f58dd7
removes hash comment id on comment replies link
decabeza Sep 19, 2017
73b61e8
adds and removes spaces :neckbeard:
decabeza Sep 19, 2017
e2c311a
Adds an unverified user to dev seeds
deivid-rodriguez Sep 17, 2017
69aaa7d
Fixes unintended new line
deivid-rodriguez Sep 17, 2017
d0528ac
Merge branch 'master' into aperez-fix-for-issue-1848
bertocq Sep 19, 2017
9b0732b
Merge pull request #1863 from wairbut-m2c/aperez-fix-for-issue-1848
bertocq Sep 19, 2017
69b7608
Merge pull request #1890 from consul/comment-reply-link
bertocq Sep 19, 2017
b416d28
Merge pull request #1883 from xarlybovi/switch-flags-ajax
voodoorai2000 Sep 20, 2017
33c687f
Merge pull request #1878 from deivid-rodriguez/chore/improve_dev_seeds
bertocq Sep 20, 2017
ca63b0b
Merge remote-tracking branch 'consul/master' into consul_pull
bertocq Sep 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
//= require legislation_annotatable
//= require watch_form_changes
//= require followable
//= require flaggable
//= require documentable
//= require tree_navigator
//= require custom
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/flaggable.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
App.Flaggable =

update: (resource_id, button) ->
$("#" + resource_id + " .js-flag-actions").html(button).foundation()
28 changes: 18 additions & 10 deletions app/assets/stylesheets/datepicker_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,30 @@
padding: 0;
z-index: 4 !important;

.ui-datepicker-prev {
left: 12px;
}

.ui-datepicker-next {
right: 12px;
}

.ui-datepicker-prev,
.ui-datepicker-next {
color: #fff;
cursor: pointer;
font-family: "icons" !important;
font-size: rem-calc(24);
font-weight: normal;
font-size: $small-font-size;
height: rem-calc(30);
line-height: $line-height;
top: 0;
position: absolute;
top: 4px;
width: rem-calc(30);

&:hover {
text-decoration: none;
}
}

.ui-datepicker-prev::after {
content: '\62';
}

.ui-datepicker-next::after {
content: '\63';
}

table {
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/admin/poll/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Admin::Poll::BaseController < Admin::BaseController
helper_method :namespace

private

def namespace
"admin"
end

end
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/booth_assignments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::BoothAssignmentsController < Admin::BaseController
class Admin::Poll::BoothAssignmentsController < Admin::Poll::BaseController

before_action :load_poll, except: [:create, :destroy]

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/poll/booths_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::BoothsController < Admin::BaseController
class Admin::Poll::BoothsController < Admin::Poll::BaseController
load_and_authorize_resource class: 'Poll::Booth'

def index
Expand Down Expand Up @@ -41,4 +41,4 @@ def booth_params
params.require(:poll_booth).permit(:name, :location, :physical)
end

end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::OfficerAssignmentsController < Admin::BaseController
class Admin::Poll::OfficerAssignmentsController < Admin::Poll::BaseController

before_action :load_poll
before_action :redirect_if_blank_required_params, only: [:by_officer]
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/poll/officers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::OfficersController < Admin::BaseController
class Admin::Poll::OfficersController < Admin::Poll::BaseController
load_and_authorize_resource :officer, class: "Poll::Officer", except: [:edit, :show]

def index
Expand Down Expand Up @@ -36,4 +36,4 @@ def show
def edit
end

end
end
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/polls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::PollsController < Admin::BaseController
class Admin::Poll::PollsController < Admin::Poll::BaseController
load_and_authorize_resource

before_action :load_search, only: [:search_booths, :search_questions, :search_officers]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/questions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::QuestionsController < Admin::BaseController
class Admin::Poll::QuestionsController < Admin::Poll::BaseController
include CommentableActions

load_and_authorize_resource :poll
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/recounts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::RecountsController < Admin::BaseController
class Admin::Poll::RecountsController < Admin::Poll::BaseController
before_action :load_poll

def index
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/admin/poll/results_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::ResultsController < Admin::BaseController
class Admin::Poll::ResultsController < Admin::Poll::BaseController
before_action :load_poll

def index
Expand All @@ -10,4 +10,4 @@ def index
def load_poll
@poll = ::Poll.includes(:questions).find(params[:poll_id])
end
end
end
4 changes: 2 additions & 2 deletions app/controllers/admin/poll/shifts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Admin::Poll::ShiftsController < Admin::BaseController
class Admin::Poll::ShiftsController < Admin::Poll::BaseController

before_action :load_booth
before_action :load_polls
Expand Down Expand Up @@ -57,4 +57,4 @@ def shift_params
params.require(:shift).permit(:booth_id, :officer_id, :date)
end

end
end
1 change: 1 addition & 0 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def destroy
def destroy_upload
@document = Document.new(cached_attachment: params[:path])
@document.set_attachment_from_cached_attachment
@document.cached_attachment = nil
@document.documentable = @documentable

if @document.attachment.destroy
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def menu_banners?
["banners"].include? controller_name
end

def menu_customization?
["pages", "images", "content_blocks"].include? controller_name
end

def official_level_options
options = [["", 0]]
(1..5).each do |i|
Expand Down
1 change: 1 addition & 0 deletions app/models/poll/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Poll::Question < ActiveRecord::Base

validates :title, presence: true
validates :author, presence: true
validates :poll_id, presence: true

validates :title, length: { minimum: 4 }
validates :description, length: { maximum: Poll::Question.description_max_length }
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<span class="icon-settings"></span>
<strong><%= t("admin.menu.title_site_customization") %></strong>
</a>
<ul <%= "class=is-active" if menu_profiles? %>>
<ul <%= "class=is-active" if menu_customization? %>>
<li <%= "class=active" if controller_name == "pages" %>>
<%= link_to t("admin.menu.site_customization.pages"), admin_site_customization_pages_path %>
</li>
Expand Down
6 changes: 3 additions & 3 deletions app/views/comments/_comment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<div class="comment-info">

<% if comment.as_administrator? %>
<span class="user-name"><%= t("comments.comment.admin") %> #<%= comment.administrator_id%></span>
<span class="user-name"><%= t("comments.comment.admin") %> #<%= comment.administrator_id %></span>
<% elsif comment.as_moderator? %>
<span class="user-name"><%= t("comments.comment.moderator") %> #<%= comment.moderator_id%></span>
<span class="user-name"><%= t("comments.comment.moderator") %> #<%= comment.moderator_id %></span>
<% else %>

<% if comment.user.hidden? || comment.user.erased? %>
Expand Down Expand Up @@ -72,7 +72,7 @@
</div>

<% if comment.children.size > 0 %>
<%= link_to "#{dom_id(comment)}", class: "js-toggle-children relative", data: {'id': "#{dom_id(comment)}"} do %>
<%= link_to "", class: "js-toggle-children relative", data: {'id': "#{dom_id(comment)}"} do %>
<span class="show-for-sr js-child-toggle" style="display: none;"><%= t("shared.show") %></span>
<span class="show-for-sr js-child-toggle"><%= t("shared.hide") %></span>
<span id="<%= dom_id(comment) %>_children_arrow" class="icon-arrow-down"></span> <%= t("comments.comment.responses", count: comment.children.size) %>
Expand Down
36 changes: 17 additions & 19 deletions app/views/proposals/_flag_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<span class="js-flag-actions">
<span class="flag-content">
<% if show_flag_action? proposal %>
<a id="flag-expand-proposal-<%= proposal.id %>" data-toggle="flag-drop-proposal-<%= proposal.id %>" title="<%= t('shared.flag') %>">
<span class="icon-flag flag-disable"></span>
</a>
<span class="dropdown-pane" id="flag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t('shared.flag'), flag_proposal_path(proposal), method: :put, remote: true, id: "flag-proposal-#{ proposal.id }" %>
</span>
<% end %>
<span class="flag-content">
<% if show_flag_action? proposal %>
<a id="flag-expand-proposal-<%= proposal.id %>" data-toggle="flag-drop-proposal-<%= proposal.id %>" title="<%= t('shared.flag') %>">
<span class="icon-flag flag-disable"></span>
</a>
<span class="dropdown-pane" id="flag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t('shared.flag'), flag_proposal_path(proposal), method: :put, remote: true, id: "flag-proposal-#{ proposal.id }" %>
</span>
<% end %>

<% if show_unflag_action? proposal %>
<a id="unflag-expand-proposal-<%= proposal.id %>" data-toggle="unflag-drop-proposal-<%= proposal.id %>" title="<%= t('shared.unflag') %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t('shared.unflag'), unflag_proposal_path(proposal), method: :put, remote: true, id: "unflag-proposal-#{ proposal.id }" %>
</span>
<% end %>
</span>
<% if show_unflag_action? proposal %>
<a id="unflag-expand-proposal-<%= proposal.id %>" data-toggle="unflag-drop-proposal-<%= proposal.id %>" title="<%= t('shared.unflag') %>">
<span class="icon-flag flag-active"></span>
</a>
<span class="dropdown-pane" id="unflag-drop-proposal-<%= proposal.id %>" data-dropdown data-auto-focus="true">
<%= link_to t('shared.unflag'), unflag_proposal_path(proposal), method: :put, remote: true, id: "unflag-proposal-#{ proposal.id }" %>
</span>
<% end %>
</span>
3 changes: 2 additions & 1 deletion app/views/proposals/_refresh_flag_actions.js.erb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
$("#<%= dom_id(@proposal) %> .js-flag-actions").html('<%= j render("proposals/flag_actions", proposal: @proposal) %>');
App.Flaggable.update("<%= dom_id(@proposal) %>",
"<%= j render("proposals/flag_actions", proposal: @proposal) %>")
4 changes: 3 additions & 1 deletion app/views/proposals/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@

<% if current_user %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= render 'proposals/flag_actions', proposal: @proposal %>
<span class="js-flag-actions">
<%= render 'proposals/flag_actions', proposal: @proposal %>
</span>
<% end %>

</div>
Expand Down
12 changes: 9 additions & 3 deletions db/dev_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def create_user(email, username = Faker::Name.name)
poll_officer.create_poll_officer
poll_officer.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: "2211111111")

level_2 = create_user('leveltwo@madrid.es', 'level 2')
create_user('unverified@consul.dev', 'unverified')

level_2 = create_user('leveltwo@consul.dev', 'level 2')
level_2.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: "2222222222", document_type: "1")

verified = create_user('verified@madrid.es', 'verified')
Expand Down Expand Up @@ -669,6 +671,7 @@ def create_user(email, username = Faker::Name.name)
end

puts " ✅"
<<<<<<< HEAD
print "Creating Probe and ProbeOptions for Town Planning project"
town_planning = Probe.create(codename: "town_planning")
town_planning_options = [
Expand Down Expand Up @@ -835,6 +838,9 @@ def create_user(email, username = Faker::Name.name)
end

puts "Creating proposal notifications"
=======
print "Creating proposal notifications"
>>>>>>> consul/master

100.times do |i|
ProposalNotification.create!(title: "Proposal notification title #{i}",
Expand Down Expand Up @@ -918,7 +924,7 @@ def create_user(email, username = Faker::Name.name)
3.times do
proposal = Proposal.reorder("RANDOM()").first
poll = Poll.current.first
question = Poll::Question.create(valid_answers: "Yes, No")
question = Poll::Question.create(valid_answers: "Yes, No", poll: poll)
question.copy_attributes_from_proposal(proposal)
question.save!
end
Expand All @@ -929,7 +935,7 @@ def create_user(email, username = Faker::Name.name)
10.times do
proposal = Proposal.reorder("RANDOM()").first
poll = Poll.current.first
question = Poll::Question.create(valid_answers: "Yes, No")
question = Poll::Question.create(valid_answers: "Yes, No", poll: poll)
question.copy_attributes_from_proposal(proposal)
question.save!
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/poll/polls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@

scenario 'Add question to poll', :js do
poll = create(:poll)
question = create(:poll_question, poll: nil, title: 'Should we rebuild the city?')
question = create(:poll_question, title: 'Should we rebuild the city?')

visit admin_poll_path(poll)

Expand Down
28 changes: 28 additions & 0 deletions spec/features/proposals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,34 @@
expect(Flag.flagged?(user, proposal)).to_not be
end

scenario 'Flagging/Unflagging AJAX', :js do
user = create(:user)
proposal = create(:proposal)

login_as(user)
visit proposal_path(proposal)

# Flagging
within "#proposal_#{proposal.id}" do
page.find("#flag-expand-proposal-#{proposal.id}").click
page.find("#flag-proposal-#{proposal.id}").click

expect(page).to have_css("#unflag-expand-proposal-#{proposal.id}")
end

expect(Flag.flagged?(user, proposal)).to be

# Unflagging
within "#proposal_#{proposal.id}" do
page.find("#unflag-expand-proposal-#{proposal.id}").click
page.find("#unflag-proposal-#{proposal.id}").click

expect(page).to have_css("#flag-expand-proposal-#{proposal.id}")
end

expect(Flag.flagged?(user, proposal)).to_not be
end

it_behaves_like "followable", "proposal", "proposal_path", { "id": "id" }

it_behaves_like "documentable", "proposal", "proposal_path", { "id": "id" }
Expand Down
30 changes: 21 additions & 9 deletions spec/models/poll/question_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
require 'rails_helper'

RSpec.describe Poll::Question, type: :model do
let(:poll_question) { build(:poll_question) }

describe "#valid_answers" do
it "gets a comma-separated string, but returns an array" do
q = create(:poll_question, valid_answers: "Yes, No")
expect(q.valid_answers).to eq(["Yes", "No"])
poll_question.valid_answers = "Yes, No"
expect(poll_question.valid_answers).to eq(["Yes", "No"])
end
end

describe "#poll_question_id" do
it "should be invalid if a poll is not selected" do
poll_question.poll_id = nil
expect(poll_question).to_not be_valid
end

it "should be valid if a poll is selected" do
poll_question.poll_id = 1
expect(poll_question).to be_valid
end
end

describe "#copy_attributes_from_proposal" do
it "copies the attributes from the proposal" do
create_list(:geozone, 3)
p = create(:proposal)
q = create(:poll_question)
q.copy_attributes_from_proposal(p)
expect(q.valid_answers).to eq(['Yes', 'No'])
expect(q.author).to eq(p.author)
expect(q.author_visible_name).to eq(p.author.name)
expect(q.proposal_id).to eq(p.id)
expect(q.title).to eq(p.title)
poll_question.copy_attributes_from_proposal(p)
expect(poll_question.valid_answers).to eq(['Yes', 'No'])
expect(poll_question.author).to eq(p.author)
expect(poll_question.author_visible_name).to eq(p.author.name)
expect(poll_question.proposal_id).to eq(p.id)
expect(poll_question.title).to eq(p.title)
end
end

Expand Down
Loading