diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 2a7676be9..a60aeb221 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -36,6 +36,8 @@ var initialize_modules = function() { }; $(function(){ + Turbolinks.enableProgressBar() + $(document).ready(initialize_modules); $(document).on('page:load', initialize_modules); $(document).on('ajax:complete', initialize_modules); diff --git a/app/assets/javascripts/rem.min.js b/app/assets/javascripts/rem.min.js new file mode 100755 index 000000000..7a96d75ed --- /dev/null +++ b/app/assets/javascripts/rem.min.js @@ -0,0 +1,7 @@ +/** + * Module: rem - v1.3.2 + * Description: A polyfill to parse CSS links and rewrite pixel equivalents into head for non supporting browsers + * Date Built: 2014-07-02 + * Copyright (c) 2014 | Chuck Carpenter ,Lucas Serven ; +**/ +!function(e){"use strict";var t=function(){var e=document.createElement("div");return e.style.cssText="font-size: 1rem;",/rem/.test(e.style.fontSize)},n=function(){for(var e=document.getElementsByTagName("link"),t=[],n=0;n0?(v=[],p=[],m=[],r()):i()}},a=function(e,t){for(var n,r=d(e).replace(/\/\*[\s\S]*?\*\//g,""),o=/[\w\d\s\-\/\\\[\]:,.'"*()<>+~%#^$_=|@]+\{[\w\d\s\-\/\\%#:!;,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!;,.'"*()]*\}/g,a=r.match(o),i=/\d*\.?\d+rem/g,s=r.match(i),c=/(.*\/)/,l=c.exec(t)[0],u=/@import (?:url\()?['"]?([^'\)"]*)['"]?\)?[^;]*/gm;null!==(n=u.exec(e));)m.push(0===n[1].indexOf("/")?n[1]:l+n[1]);null!==a&&0!==a.length&&(f=f.concat(a),g=g.concat(s))},i=function(){for(var e=/[\w\d\s\-\/\\%#:,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!,.'"*()]*[;}]/g,t=0;t #mq-test-1 { width: 42px; }',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){v(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))},g=function(a){return a.replace(c.regex.minmaxwh,"").match(c.regex.other)};if(c.ajax=f,c.queue=d,c.unsupportedmq=g,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,comments:/\/\*[^*]*\*+([^/][^*]*\*+)*\//gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,maxw:/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,minmaxwh:/\(\s*m(in|ax)\-(height|width)\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/gi,other:/\([^\)]*\)/g},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var h,i,j,k=a.document,l=k.documentElement,m=[],n=[],o=[],p={},q=30,r=k.getElementsByTagName("head")[0]||l,s=k.getElementsByTagName("base")[0],t=r.getElementsByTagName("link"),u=function(){var a,b=k.createElement("div"),c=k.body,d=l.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=k.createElement("body"),c.style.background="none"),l.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&l.insertBefore(c,l.firstChild),a=b.offsetWidth,f?l.removeChild(c):c.removeChild(b),l.style.fontSize=d,e&&(c.style.fontSize=e),a=j=parseFloat(a)},v=function(b){var c="clientWidth",d=l[c],e="CSS1Compat"===k.compatMode&&d||k.body[c]||d,f={},g=t[t.length-1],p=(new Date).getTime();if(b&&h&&q>p-h)return a.clearTimeout(i),i=a.setTimeout(v,q),void 0;h=p;for(var s in m)if(m.hasOwnProperty(s)){var w=m[s],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?j||u():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?j||u():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(n[w.rules]))}for(var C in o)o.hasOwnProperty(C)&&o[C]&&o[C].parentNode===r&&r.removeChild(o[C]);o.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=k.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,r.insertBefore(E,g.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(k.createTextNode(F)),o.push(E)}},w=function(a,b,d){var e=a.replace(c.regex.comments,"").replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var h=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},i=!f&&d;b.length&&(b+="/"),i&&(f=1);for(var j=0;f>j;j++){var k,l,o,p;i?(k=d,n.push(h(a))):(k=e[j].match(c.regex.findStyles)&&RegExp.$1,n.push(RegExp.$2&&h(RegExp.$2))),o=k.split(","),p=o.length;for(var q=0;p>q;q++)l=o[q],g(l)||m.push({media:l.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:n.length-1,hasquery:l.indexOf("(")>-1,minw:l.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:l.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}v()},x=function(){if(d.length){var b=d.shift();f(b.href,function(c){w(c,b.href,b.media),p[b.href]=!0,a.setTimeout(function(){x()},0)})}},y=function(){for(var b=0;b= 2 + redirect_to account_path, alert: t('verification.letter.alert.verify_attemps_left') + end + end end \ No newline at end of file diff --git a/app/controllers/verification/sms_controller.rb b/app/controllers/verification/sms_controller.rb index 8b4d24b9f..9f282c2c9 100644 --- a/app/controllers/verification/sms_controller.rb +++ b/app/controllers/verification/sms_controller.rb @@ -27,6 +27,7 @@ class Verification::SmsController < ApplicationController @sms = Verification::Sms.new(sms_params.merge(user: current_user)) if @sms.verify? current_user.update(confirmed_phone: current_user.unconfirmed_phone) + ahoy.track :level_2_user, user_id: current_user.id if VerifiedUser.phone?(current_user) current_user.update(verified_at: Time.now) diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index 077890600..a64fe7220 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -18,13 +18,17 @@ class Verification::Letter end def letter_requested! - user.update(letter_requested_at: Time.now, letter_verification_code: four_digit_code) + user.update(letter_requested_at: Time.now, letter_verification_code: generate_verification_code) end def verify? user.letter_verification_code == verification_code end + def increase_letter_verification_tries + user.update(letter_verification_tries: user.letter_verification_tries += 1) + end + def update_user_address user.address = Address.new(parsed_address) user.save @@ -50,8 +54,10 @@ class Verification::Letter district: address[:nombre_distrito] } end - def four_digit_code - rand.to_s[2..5] - end + private + + def generate_verification_code + rand.to_s[2..7] + end end diff --git a/app/models/verification/sms.rb b/app/models/verification/sms.rb index f280f115e..7b032661b 100644 --- a/app/models/verification/sms.rb +++ b/app/models/verification/sms.rb @@ -24,7 +24,7 @@ class Verification::Sms end def update_user_phone_information - user.update(unconfirmed_phone: phone, sms_confirmation_code: four_digit_code) + user.update(unconfirmed_phone: phone, sms_confirmation_code: generate_confirmation_code) end def send_sms @@ -41,7 +41,7 @@ class Verification::Sms private - def four_digit_code + def generate_confirmation_code rand.to_s[2..5] end end \ No newline at end of file diff --git a/app/views/admin/moderators/_moderator.html.erb b/app/views/admin/moderators/_moderator.html.erb index 00fd9c602..df30c624f 100644 --- a/app/views/admin/moderators/_moderator.html.erb +++ b/app/views/admin/moderators/_moderator.html.erb @@ -1,5 +1,5 @@ <%= moderator.name %> - •  + •  <%= moderator.email %> <% if moderator.persisted? %> <%= link_to t('admin.moderators.moderator.delete'), diff --git a/app/views/admin/officials/index.html.erb b/app/views/admin/officials/index.html.erb index b5e5efddb..5e4e2e443 100644 --- a/app/views/admin/officials/index.html.erb +++ b/app/views/admin/officials/index.html.erb @@ -17,9 +17,9 @@ <% @officials.each do |official| %>
  • <%= link_to official.name, edit_admin_official_path(official) %> -  •  +  •  <%= t("admin.officials.level_#{official.official_level}") %> -  •  +  •  <%= official.official_position %> diff --git a/app/views/admin/officials/search.html.erb b/app/views/admin/officials/search.html.erb index 028ba065b..f2636a52e 100644 --- a/app/views/admin/officials/search.html.erb +++ b/app/views/admin/officials/search.html.erb @@ -17,11 +17,11 @@ <% @users.each do |user| %>
  • <%= link_to user.name, edit_admin_official_path(user) %> -  •  +  •  <%= user.official_position %> -  •  +  •  <%= t("admin.officials.level_#{user.official_level}") %> <%= link_to user.official? ? t("admin.officials.search.edit_official") : t("admin.officials.search.make_official"), edit_admin_official_path(user), class: "button radius tiny right" %> diff --git a/app/views/comments/_actions.html.erb b/app/views/comments/_actions.html.erb index 72a458f52..36ec42e01 100644 --- a/app/views/comments/_actions.html.erb +++ b/app/views/comments/_actions.html.erb @@ -4,13 +4,13 @@ <% if can? :hide, comment %> -  •  +  •  <%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment), method: :put, remote: true, data: { confirm: t('admin.actions.confirm') } %> <% end %> <% if can? :hide, comment.user %> -  •  +  •  <%= link_to t("admin.actions.hide_author").capitalize, hide_moderation_user_path(comment.user_id, debate_id: @debate.id), method: :put, data: { confirm: t('admin.actions.confirm') } %> <% end %> diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 0ac6b9be1..3997efdaf 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -38,20 +38,20 @@ <% else %> <%= comment.user.name %> <% if comment.user.official? %> -  •  +  •  <%= comment.user.official_position %> <% end %> <% end %> <% if comment.user.verified_organization? %> -  •  +  •  <%= t("shared.collective") %> <% end %> <% if comment.user_id == @commentable.author_id %> -  •  +  •  <%= t("debates.comment.author") %> @@ -59,7 +59,7 @@ <% end %> -  •  +  •  <% if comment.as_administrator? %> diff --git a/app/views/debates/_debate.html.erb b/app/views/debates/_debate.html.erb index 49d202cc8..0d2cef4ce 100644 --- a/app/views/debates/_debate.html.erb +++ b/app/views/debates/_debate.html.erb @@ -11,7 +11,7 @@

      <%= link_to t("debates.debate.comments", count: debate.comments_count), debate_path(debate, anchor: "comments") %> -  •  +  •  <%= l debate.created_at.to_date %>

    diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 1c48ea214..83c37964a 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -32,7 +32,7 @@ <%= @debate.author.name %> <% if @debate.author.official? %> -  •  +  •  <%= @debate.author.official_position %> @@ -40,18 +40,18 @@ <% end %> <% if @debate.author.verified_organization? %> -  •  +  •  <%= t("shared.collective") %> <% end %> -  •  +  •  <%= l @debate.created_at.to_date %> -  •  +  •    <%= link_to t("debates.show.comments", count: @debate.comments_count), "#comments" %> -  •  +  •  <%= render 'debates/flag_actions', debate: @debate %> diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index f341f4bd0..f71c6b8ee 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -13,7 +13,6 @@ open_source: link_to(t("layouts.footer.open_source"), t("layouts.footer.open_source_url"), target: "blank"), github: link_to(t("layouts.footer.github"), t("layouts.footer.github_url"), target: "blank")).html_safe %> -
    <%= t("layouts.footer.contact_us") %> <%= mail_to "web.gobiernoabierto@madrid.es" %>

    diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index fa9f1852d..860bf791a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,7 +14,10 @@ rel: "apple-touch-icon", sizes: "200x200", type: "image/png" %> - + + ">
    <%= render 'layouts/header' %> @@ -48,4 +51,7 @@ <%= render 'layouts/footer' %>
    + diff --git a/app/views/moderation/bulk/index.html.erb b/app/views/moderation/bulk/index.html.erb index c3bb68777..5451d4b1c 100644 --- a/app/views/moderation/bulk/index.html.erb +++ b/app/views/moderation/bulk/index.html.erb @@ -24,9 +24,9 @@ <%= link_to debate.title, debate, target: "_blank" %> -  •  +  •  <%= debate.author.username %> -  •  +  •  <%= l debate.updated_at.to_date %>
    <%= debate.description %> diff --git a/app/views/moderation/users/index.html.erb b/app/views/moderation/users/index.html.erb index 5a49c16d1..18f4f5f67 100644 --- a/app/views/moderation/users/index.html.erb +++ b/app/views/moderation/users/index.html.erb @@ -19,7 +19,7 @@ <% @users.each do |user| %>
  • <%= user.name %> -  •  +  •  <% if user.hidden? %> <%= t("moderation.users.index.hidden") %> <% else %> diff --git a/app/views/stats/show.html.erb b/app/views/stats/show.html.erb index f5df82b98..da366aa1a 100644 --- a/app/views/stats/show.html.erb +++ b/app/views/stats/show.html.erb @@ -10,13 +10,13 @@

    Combined

    - <%= events_chart_tag @event_types, id: 'combined' %> + <%= events_chart_tag @event_types.keys, id: 'combined' %>
    - <% @event_types.each do |event_type| %> -

    <%= event_type.titleize %>

    - <%= events_chart_tag event_type %> + <% @event_types.each do |event, count| %> +

    <%= event.titleize %> (<%= count %>)

    + <%= events_chart_tag event %> <% end %>
    diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 09ba7401a..0822fb9a1 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,7 +1,7 @@ set :deploy_to, deploysecret(:deploy_to) set :server_name, deploysecret(:server_name) set :db_server, deploysecret(:db_server) -set :branch, :master +set :branch, ENV['branch'] || :master set :ssh_options, port: deploysecret(:ssh_port) set :stage, :staging set :rails_env, :staging diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index dcccf9429..7ad1bbb22 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -2,7 +2,7 @@ ActsAsTaggableOn::Tagging.class_eval do after_destroy :touch_taggable def touch_taggable - taggable.touch + taggable.touch if taggable.present? end end \ No newline at end of file diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index a6dfa75c0..e79eaca70 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -10,3 +10,4 @@ Rails.application.config.assets.version = '1.0' # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # Rails.application.config.assets.precompile += %w( search.js ) Rails.application.config.assets.precompile += %w( ckeditor/* ) +Rails.application.config.assets.precompile += %w( rem.min.js, respond.min.js ) \ No newline at end of file diff --git a/config/locales/verification.en.yml b/config/locales/verification.en.yml index bcc818d97..3480d5a4c 100644 --- a/config/locales/verification.en.yml +++ b/config/locales/verification.en.yml @@ -83,6 +83,7 @@ en: success: "Correct code. Your account is verified" alert: unconfirmed_code: "You have not yet enter the confirmation code" + verify_attemps_left: "You have reached the maximum number of letter verification tries" verified_user: show: title: "Available information" diff --git a/config/locales/verification.es.yml b/config/locales/verification.es.yml index 75442af5d..e500bc33d 100644 --- a/config/locales/verification.es.yml +++ b/config/locales/verification.es.yml @@ -83,6 +83,7 @@ es: success: "Código correcto. Tu cuenta ya está verificada" alert: unconfirmed_code: "Todavía no has introducido el código de confirmación" + verify_attemps_left: "Has llegado al máximo número de intentos de verificar tu carta." verified_user: show: title: "Información disponible" diff --git a/db/migrate/20150910092713_add_letter_verification_tries_to_users.rb b/db/migrate/20150910092713_add_letter_verification_tries_to_users.rb new file mode 100644 index 000000000..622ce6b2d --- /dev/null +++ b/db/migrate/20150910092713_add_letter_verification_tries_to_users.rb @@ -0,0 +1,5 @@ +class AddLetterVerificationTriesToUsers < ActiveRecord::Migration + def change + add_column :users, :letter_verification_tries, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index b23ad3c05..a9ca5d4b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150909153455) do +ActiveRecord::Schema.define(version: 20150910092713) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -238,6 +238,7 @@ ActiveRecord::Schema.define(version: 20150909153455) do t.datetime "letter_requested_at" t.datetime "confirmed_hide_at" t.string "letter_verification_code" + t.integer "letter_verification_tries", default: 0 end add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree diff --git a/spec/features/admin/tags_spec.rb b/spec/features/admin/tags_spec.rb new file mode 100644 index 000000000..a56f10ffa --- /dev/null +++ b/spec/features/admin/tags_spec.rb @@ -0,0 +1,84 @@ +require 'rails_helper' + +feature 'Admin tags' do + + background do + @tag1 = create(:tag) + login_as(create(:administrator).user) + end + + scenario 'Index' do + create(:debate, tag_list: 'supertag') + visit admin_tags_path + + expect(page).to have_content @tag1.name + expect(page).to have_content 'supertag' + end + + scenario 'Create' do + visit admin_tags_path + + expect(page).to_not have_content 'important issues' + + within("form.new_tag") do + fill_in "tag_name", with: 'important issues' + click_button 'Create Topic' + end + + visit admin_tags_path + + expect(page).to have_content 'important issues' + end + + scenario 'Update' do + visit admin_tags_path + featured_checkbox = find("#tag_featured_#{@tag1.id}") + expect(featured_checkbox.checked?).to be_nil + + within("#edit_tag_#{@tag1.id}") do + check "tag_featured_#{@tag1.id}" + click_button 'Update Topic' + end + + visit admin_tags_path + featured_checkbox = find("#tag_featured_#{@tag1.id}") + expect(featured_checkbox.checked?).to eq('checked') + end + + scenario 'Delete' do + tag2 = create(:tag, name: 'bad tag') + create(:debate, tag_list: tag2.name) + visit admin_tags_path + + expect(page).to have_content @tag1.name + expect(page).to have_content tag2.name + + within("#edit_tag_#{tag2.id}") do + click_link 'Delete Topic' + end + + visit admin_tags_path + expect(page).to have_content @tag1.name + expect(page).to_not have_content tag2.name + end + + scenario 'Delete tag with hidden taggables' do + tag2 = create(:tag, name: 'bad tag') + debate = create(:debate, tag_list: tag2.name) + debate.hide + + visit admin_tags_path + + expect(page).to have_content @tag1.name + expect(page).to have_content tag2.name + + within("#edit_tag_#{tag2.id}") do + click_link 'Delete Topic' + end + + visit admin_tags_path + expect(page).to have_content @tag1.name + expect(page).to_not have_content tag2.name + end + +end \ No newline at end of file diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 800a624d6..edb5c2725 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -360,59 +360,59 @@ feature 'Debates' do feature 'Debate index order filters' do scenario 'Default order is confidence_score', :js do - create(:debate, title: 'best').update_column(:confidence_score, 10) - create(:debate, title: 'worst').update_column(:confidence_score, 2) - create(:debate, title: 'medium').update_column(:confidence_score, 5) + create(:debate, title: 'Best').update_column(:confidence_score, 10) + create(:debate, title: 'Worst').update_column(:confidence_score, 2) + create(:debate, title: 'Medium').update_column(:confidence_score, 5) visit debates_path - expect('best').to appear_before('medium') - expect('medium').to appear_before('worst') + expect('Best').to appear_before('Medium') + expect('Medium').to appear_before('Worst') end scenario 'Debates are ordered by hot_score', :js do - create(:debate, title: 'best').update_column(:hot_score, 10) - create(:debate, title: 'worst').update_column(:hot_score, 2) - create(:debate, title: 'medium').update_column(:hot_score, 5) + create(:debate, title: 'Best').update_column(:hot_score, 10) + create(:debate, title: 'Worst').update_column(:hot_score, 2) + create(:debate, title: 'Medium').update_column(:hot_score, 5) visit debates_path select 'most active', from: 'order-selector' within '#debates.js-order-hot-score' do - expect('best').to appear_before('medium') - expect('medium').to appear_before('worst') + expect('Best').to appear_before('Medium') + expect('Medium').to appear_before('Worst') end expect(current_url).to include('order=hot_score') end scenario 'Debates are ordered by most commented', :js do - create(:debate, title: 'best', comments_count: 10) - create(:debate, title: 'medium', comments_count: 5) - create(:debate, title: 'worst', comments_count: 2) + create(:debate, title: 'Best', comments_count: 10) + create(:debate, title: 'Medium', comments_count: 5) + create(:debate, title: 'Worst', comments_count: 2) visit debates_path select 'most commented', from: 'order-selector' within '#debates.js-order-most-commented' do - expect('best').to appear_before('medium') - expect('medium').to appear_before('worst') + expect('Best').to appear_before('Medium') + expect('Medium').to appear_before('Worst') end expect(current_url).to include('order=most_commented') end scenario 'Debates are ordered by newest', :js do - create(:debate, title: 'best', created_at: Time.now) - create(:debate, title: 'medium', created_at: Time.now - 1.hour) - create(:debate, title: 'worst', created_at: Time.now - 1.day) + create(:debate, title: 'Best', created_at: Time.now) + create(:debate, title: 'Medium', created_at: Time.now - 1.hour) + create(:debate, title: 'Worst', created_at: Time.now - 1.day) visit debates_path select 'newest', from: 'order-selector' within '#debates.js-order-created-at' do - expect('best').to appear_before('medium') - expect('medium').to appear_before('worst') + expect('Best').to appear_before('Medium') + expect('Medium').to appear_before('Worst') end expect(current_url).to include('order=created_at') diff --git a/spec/features/stats_spec.rb b/spec/features/stats_spec.rb new file mode 100644 index 000000000..2363e3ff6 --- /dev/null +++ b/spec/features/stats_spec.rb @@ -0,0 +1,21 @@ +require 'rails_helper' + +feature 'Stats' do + + scenario 'Level 2 user' do + admin = create(:administrator) + user = create(:user) + login_as(user) + + visit account_path + click_link 'Verify my account' + verify_residence + confirm_phone + + login_as(admin.user) + visit stats_path + + expect(page).to have_content "Level 2 User (1)" + end + +end \ No newline at end of file diff --git a/spec/features/verification/letter_spec.rb b/spec/features/verification/letter_spec.rb index b62ae00f8..eb1392714 100644 --- a/spec/features/verification/letter_spec.rb +++ b/spec/features/verification/letter_spec.rb @@ -76,4 +76,24 @@ feature 'Verify Letter' do expect(URI.parse(current_url).path).to eq(new_sms_path) end + scenario '3 tries allowed' do + user = create(:user, residence_verified_at: Time.now, confirmed_phone: "611111111") + login_as(user) + + visit new_letter_path + click_button 'Send me a letter with the code' + + 3.times do + fill_in 'letter_verification_code', with: "999999" + click_button 'Send' + end + + expect(page).to have_content 'You have reached the maximum number of letter verification tries' + expect(URI.parse(current_url).path).to eq(account_path) + + visit new_letter_path + expect(page).to have_content 'You have reached the maximum number of letter verification tries' + expect(URI.parse(current_url).path).to eq(account_path) + end + end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 4753abbbb..c1d382b4e 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -110,4 +110,17 @@ module CommonActions click_button 'Verify residence' expect(page).to have_content 'Residence verified' end + + def confirm_phone + fill_in 'sms_phone', with: "611111111" + click_button 'Send' + + expect(page).to have_content 'Security code confirmation' + + user = User.last.reload + fill_in 'sms_confirmation_code', with: user.sms_confirmation_code + click_button 'Send' + + expect(page).to have_content 'Correct code' + end end