From 6e14348d16cf2d7cd3a981f2483006eddf605d1a Mon Sep 17 00:00:00 2001 From: cblanc Date: Sun, 26 Apr 2015 11:34:37 +0100 Subject: [PATCH 01/76] Ignore gemsets and directory env variables --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index d4d3e2e..e76151e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /tmp/* /spec/tmp/* .ruby-version +.ruby-gemset .env .tmp* .rspec @@ -40,3 +41,6 @@ /index/* rerun.txt pickle-email-*.html + +# Direnv +.envrc \ No newline at end of file From 4b30970dde58dae3a1e489c95cf0398baadb9bfe Mon Sep 17 00:00:00 2001 From: cblanc Date: Sun, 26 Apr 2015 11:35:02 +0100 Subject: [PATCH 02/76] Update poltergeist (current version uses out of date phantomjs) --- Gemfile | 2 +- Gemfile.lock | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index f22590d..b161b85 100644 --- a/Gemfile +++ b/Gemfile @@ -62,7 +62,7 @@ group :test do gem 'database_cleaner', '~> 1.2.0' gem 'rspec-rails', '~> 2.14.1' gem 'capybara', '~> 2.2.1' - gem 'poltergeist', '~> 1.5.0' + gem 'poltergeist', '~> 1.6.0' gem 'selenium-webdriver', '~> 2.41.0' gem 'factory_girl_rails', '~> 4.4.1' gem 'timecop', '~> 0.7.1' diff --git a/Gemfile.lock b/Gemfile.lock index 70af6dc..a090d97 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -149,7 +149,7 @@ GEM nokogiri (1.6.1) mini_portile (~> 0.5.0) oj (2.5.5) - poltergeist (1.5.0) + poltergeist (1.6.0) capybara (~> 2.1) cliver (~> 0.3.1) multi_json (~> 1.0) @@ -249,7 +249,9 @@ GEM execjs (>= 0.3.0) json (>= 1.8.0) websocket (1.0.7) - websocket-driver (0.3.3) + websocket-driver (0.5.4) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) will_paginate (3.0.5) xpath (2.0.0) nokogiri (~> 1.3) @@ -290,7 +292,7 @@ DEPENDENCIES newrelic_rpm (~> 3.7.2.195) nokogiri (~> 1.6.1) oj (~> 2.5.5) - poltergeist (~> 1.5.0) + poltergeist (~> 1.6.0) pry-byebug (~> 1.3.2) puma (~> 2.11.1) quiet_assets (~> 1.0.2) From 699b5c612f3c4a7c524ba9d3b5e5677f5233ce68 Mon Sep 17 00:00:00 2001 From: cblanc Date: Sun, 26 Apr 2015 11:36:18 +0100 Subject: [PATCH 03/76] Cleanup --- app/assets/javascripts/local.js | 71 --------------------------------- 1 file changed, 71 deletions(-) diff --git a/app/assets/javascripts/local.js b/app/assets/javascripts/local.js index 40ba551..d15009a 100644 --- a/app/assets/javascripts/local.js +++ b/app/assets/javascripts/local.js @@ -1,75 +1,4 @@ $(document).ready(function(){ - // - //function showNews(source, cat, content){ - // new Ajax.Updater(content, '/categories/' + cat, { - // method: 'get' - // }); - // var thisChild = source.parentNode.firstChild; - // while (thisChild != source.parentNode.lastChild) { - // if (thisChild.nodeType == 1 && thisChild.getAttribute("class") != "unread") { - // thisChild.setAttribute("class", ""); - // } - // thisChild = thisChild.nextSibling; - // } - // source.setAttribute("class", "active"); - //} - - //function goToTheEnd(){ - // var ed = tinyMCE.activeEditor; - // // This gets the root node of the editor window - // var root = ed.dom.getRoot(); - // // And this gets the last node inside of it, so the last

...

tag - // var lastnode = root.childNodes[root.childNodes.length - 1]; - // - // if (tinymce.isGecko) { - // // But firefox places the selection outside of that tag, so we need to go one level deeper: - // lastnode = lastnode.childNodes[lastnode.childNodes.length - 1]; - // } - // // Now, we select the node - // ed.selection.select(lastnode); - // // And collapse the selection to the end to put the caret there: - // ed.selection.collapse(false); - //} - // - //var myrules = { - // '.remove': function(e){ - // el = Event.findElement(e); - // target = el.href.replace(/.*#/, '.') - // el.up(target).hide(); - // if (hidden_input = el.previous("input[type=hidden]")) { - // hidden_input.value = '1' - // } - // } - //}; - // - //Event.observe(window, 'load', function(){ - // $('container').delegate('click', myrules); - //}); - // - //function changeCssClass(id, newclass){ - // var obj = document.getElementById(id) - // obj.setAttribute("class", newclass); - // obj.setAttribute("className", newclass); - // obj.className = newclass; - //}; - // - //function changeTab(container, tab){ - // $(tab).style.visibility = 'hidden'; - //}; - // - //function Trash(source){ - // var input = document.createElement("input"); - // input.name = "deleted[reason]"; - // input.type = "hidden"; - // input.value = prompt('Enter reason', 'Violation of rule #'); - // if (input.value == null) { - // return - // } - // source.appendChild(input); - // source.submit(); - //} - - // User popup var userInfoTimeout; From f87fc9ae58ba0df12e66d47a94c52eaa6fac7264 Mon Sep 17 00:00:00 2001 From: cblanc Date: Mon, 27 Apr 2015 23:32:27 +0100 Subject: [PATCH 04/76] Added some simple integration tests for shout messages --- spec/features/shoutbox/shoutbox_spec.rb | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/features/shoutbox/shoutbox_spec.rb diff --git a/spec/features/shoutbox/shoutbox_spec.rb b/spec/features/shoutbox/shoutbox_spec.rb new file mode 100644 index 0000000..30d75ac --- /dev/null +++ b/spec/features/shoutbox/shoutbox_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +feature 'Shoutbox' do + background do + @user = create :user + sign_in_as @user + visit root_path + end + + feature 'user creates a shout', js: true do + scenario 'shouting with valid content' do + shout = rand(100000).to_s + fill_in 'shoutbox_text', with: shout + click_button 'Shout!' + expect(page).to have_content(shout) + end + + scenario 'unable to while banned' do + @user.bans.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days + shout = rand(100000).to_s + fill_in 'shoutbox_text', with: shout + click_button 'Shout!' + expect(page).to_not have_content(shout) + end + end +end \ No newline at end of file From d268eedc608f9b8db9fa5d7d1720def1396e647b Mon Sep 17 00:00:00 2001 From: cblanc Date: Mon, 27 Apr 2015 23:36:27 +0100 Subject: [PATCH 05/76] Move shoutmsg polling invocation to instances where shoutbox is available --- app/assets/javascripts/local.js | 8 -------- app/views/widgets/_shoutbox.html.erb | 13 ++++++++++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/local.js b/app/assets/javascripts/local.js index d15009a..d21797c 100644 --- a/app/assets/javascripts/local.js +++ b/app/assets/javascripts/local.js @@ -24,14 +24,6 @@ $(document).ready(function(){ function HideUserPopupRunner(){ document.getElementById("userPopup").style.visibility = "Hidden"; } - - // Shoutbox - $.PeriodicalUpdater("/shoutmsgs/index.js", { - method: "GET", - type: "script", - minTimeout: 10000, - multiplier: 2 - }); }); $(function() { diff --git a/app/views/widgets/_shoutbox.html.erb b/app/views/widgets/_shoutbox.html.erb index 606b88e..0bf5238 100644 --- a/app/views/widgets/_shoutbox.html.erb +++ b/app/views/widgets/_shoutbox.html.erb @@ -8,4 +8,15 @@ <%= render partial: "shoutmsgs/new", locals: { shoutmsg: Shoutmsg.new } %> <%= link_to "Shoutbox Recent History", controller: :shoutmsgs, action: "index" %>
<%= link_to "Shoutbox Rules", article_path(Article::SB_RULES) %> - \ No newline at end of file + + + \ No newline at end of file From da6024f162ff2240d6038303b710f74c1cac885a Mon Sep 17 00:00:00 2001 From: simplefl Date: Mon, 27 Apr 2015 20:34:39 +0200 Subject: [PATCH 06/76] Display channel password on gather page. --- app/views/gathers/show.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/gathers/show.html.erb b/app/views/gathers/show.html.erb index 8fad528..1d5d62e 100644 --- a/app/views/gathers/show.html.erb +++ b/app/views/gathers/show.html.erb @@ -150,6 +150,7 @@
  • <%= link_to "Teamspeak 3", "http://www.teamspeak.com/?page=downloads" %>
  • Server: ensl.org
  • +
  • Channel password: ns2gather
From b6d932310fb82e39496b0f572a7ece226a471ee7 Mon Sep 17 00:00:00 2001 From: simplefl Date: Tue, 28 Apr 2015 17:51:22 +0200 Subject: [PATCH 07/76] Pump rmagick to 2.13.4. --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b161b85..ae4dda3 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem 'will_paginate', '~> 3.0.5' gem 'dynamic_form', '~> 1.1.4' gem 'country_code_select', '~> 1.0.1' gem 'active_link_to', '~> 1.0.2' -gem 'rmagick', '~> 2.13.2', require: false +gem 'rmagick', '~> 2.13.4', require: false gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby' # Please install nodejs locally. From 932652a7268d7296ceaaec414d092479b7cef2b7 Mon Sep 17 00:00:00 2001 From: cblanc Date: Sat, 2 May 2015 18:07:10 +0100 Subject: [PATCH 08/76] Fix error page for when the 404 is user not found --- app/views/layouts/errors.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/layouts/errors.html.erb b/app/views/layouts/errors.html.erb index b647100..d20070d 100644 --- a/app/views/layouts/errors.html.erb +++ b/app/views/layouts/errors.html.erb @@ -6,13 +6,13 @@ <%= favicon_link_tag 'shared/favicon.ico' %> - <%= stylesheet_link_tag "themes/#{active_theme}/errors" %> + <%= stylesheet_link_tag "themes/default/errors" %>

<%= params[:code] %>

From dc88b78739241612ce77d3367bb5f81ebdb5ca0e Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Sat, 2 May 2015 23:46:16 +0100 Subject: [PATCH 09/76] Addec colour and documentaton style formatting to RSpec output to improve readability --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e31306e..f2956e2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -31,6 +31,8 @@ RSpec.configure do |config| config.fixture_path = "#{::Rails.root}/spec/fixtures" config.order = 'random' config.use_transactional_fixtures = false + config.color = true + config.formatter = :documentation config.before(:each) do events_list_json = JSON.parse(File.read(Rails.root.join('spec/fixtures/google_calendar.json'))) From 0485cbaf8af267769d782d351bbc3acd201ebc4a Mon Sep 17 00:00:00 2001 From: cblanc Date: Tue, 5 May 2015 20:35:54 +0100 Subject: [PATCH 10/76] render_shoutmsgs never invoked --- app/controllers/shoutmsgs_controller.rb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/app/controllers/shoutmsgs_controller.rb b/app/controllers/shoutmsgs_controller.rb index 06a1e93..041116c 100644 --- a/app/controllers/shoutmsgs_controller.rb +++ b/app/controllers/shoutmsgs_controller.rb @@ -29,11 +29,4 @@ class ShoutmsgsController < ApplicationController @shoutmsg.destroy redirect_to_back end - - - private - - def render_shoutmsgs shoutable_type = nil, shoutable_id = nil - - end end From b9ecfb229220b13e200f31e4049f4a0b5194af56 Mon Sep 17 00:00:00 2001 From: cblanc Date: Tue, 5 May 2015 22:43:54 +0100 Subject: [PATCH 11/76] Added test to find out how banning works --- spec/models/user_spec.rb | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 spec/models/user_spec.rb diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..24ba3a2 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,44 @@ +# == Schema Information +# +# Table name: users +# +# id :integer not null, primary key +# username :string(255) +# password :string(255) +# firstname :string(255) +# lastname :string(255) +# email :string(255) +# steamid :string(255) +# team_id :integer +# lastvisit :datetime +# created_at :datetime +# updated_at :datetime +# lastip :string(255) +# country :string(255) +# birthdate :date +# time_zone :string(255) +# version :integer +# public_email :boolean default(FALSE), not null +# + +require 'spec_helper' + +describe User do + let!(:user) { create :user } + + describe "#banned?" do + it "returns false if user is not banned" do + expect(user.banned?).to be_false + end + + it "returns true if user is banned" do + ban = Ban.create! ban_type: Ban::TYPE_SITE, expiry: Time.now + 10.days, user_name: user.username + expect(user.banned?).to be_true + end + + it "returns true for specific bans" do + ban = Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username + expect(user.banned? Ban::TYPE_MUTE).to be_true + end + end +end \ No newline at end of file From 79933f6251389cb839fb54bd6aeb2dcd14e948c6 Mon Sep 17 00:00:00 2001 From: cblanc Date: Tue, 5 May 2015 22:51:10 +0100 Subject: [PATCH 12/76] Bundle installed --- Gemfile.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a090d97..0701597 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,7 +193,7 @@ GEM rake (10.3.2) rdoc (3.12.2) json (~> 1.4) - rmagick (2.13.2) + rmagick (2.13.4) rspec-core (2.14.8) rspec-expectations (2.14.5) diff-lcs (>= 1.1.3, < 2.0) @@ -298,7 +298,7 @@ DEPENDENCIES quiet_assets (~> 1.0.2) rails (~> 3.2.19) rails_autolink (~> 1.1.5) - rmagick (~> 2.13.2) + rmagick (~> 2.13.4) rspec-rails (~> 2.14.1) sanitize (~> 2.1.0) sass (~> 3.3.4) From e69c4c9b61ff56b36c680bcaa3302355427844e3 Mon Sep 17 00:00:00 2001 From: cblanc Date: Tue, 5 May 2015 22:51:26 +0100 Subject: [PATCH 13/76] Updated test for expected ban behaviour --- spec/features/shoutbox/shoutbox_spec.rb | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/spec/features/shoutbox/shoutbox_spec.rb b/spec/features/shoutbox/shoutbox_spec.rb index 30d75ac..dec6542 100644 --- a/spec/features/shoutbox/shoutbox_spec.rb +++ b/spec/features/shoutbox/shoutbox_spec.rb @@ -1,26 +1,23 @@ require 'spec_helper' -feature 'Shoutbox' do +feature 'Shoutbox', js: true do + let!(:user) { create :user } + background do - @user = create :user - sign_in_as @user - visit root_path + sign_in_as user end - feature 'user creates a shout', js: true do - scenario 'shouting with valid content' do - shout = rand(100000).to_s - fill_in 'shoutbox_text', with: shout - click_button 'Shout!' - expect(page).to have_content(shout) - end + scenario 'creating a valid shout' do + visit root_path + shout = rand(100000).to_s + fill_in 'shoutbox_text', with: shout + click_button 'Shout!' + expect(page).to have_content(shout) + end - scenario 'unable to while banned' do - @user.bans.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days - shout = rand(100000).to_s - fill_in 'shoutbox_text', with: shout - click_button 'Shout!' - expect(page).to_not have_content(shout) - end - end + scenario 'creating shout while banned' do + Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username + visit root_path + expect(find("#sidebar")).to have_content "You have been muted." + end end \ No newline at end of file From 44109675ae64cbe56d1cef5f6d1f1ba645f2830d Mon Sep 17 00:00:00 2001 From: cblanc Date: Wed, 6 May 2015 00:04:41 +0100 Subject: [PATCH 14/76] Cleanup: move out js, require_self shouldnt be necessary --- app/assets/javascripts/application.js.coffee | 42 +------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index cc5b14b..8cb6a1b 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -6,43 +6,5 @@ //= require tinymce-jquery //= require yetii //= require local -//= require_self - -$ -> - $('#logout').click -> - $(this).closest('form').submit() - - $('select').each (i, el) -> - $select = $(el) - - $select.wrap '
' - $select.on 'DOMSubtreeModified', (event) -> - $el = $(this) - $wrapper = $el.parent() - - if $el.is("[disabled]") - $wrapper.addClass 'disabled' - else - $wrapper.removeClass 'disabled' - - $select.trigger 'DOMSubtreeModified' - - $('a[href=#form_submit]').click -> - $(this).closest('form').submit() - return false - - $('select.autosubmit').change -> - $(this).closest('form').submit() - - $('#notification').delay(3000).fadeOut() - - $('#steam-search a').click (event) -> - event.preventDefault() - - $search = $('#steam-search') - id = $search.data 'user-id' - - $search.html "

Searching...

" - - $.get "/api/v1/users/#{id}", (data) -> - $search.html "Steam Profile: #{data.steam.nickname}" +//= require shoutbox +//= require misc \ No newline at end of file From 5f06775a26343f212b519a0f85e8760ef9b4563e Mon Sep 17 00:00:00 2001 From: cblanc Date: Wed, 6 May 2015 00:05:03 +0100 Subject: [PATCH 15/76] Cleanup: move out js, require_self shouldnt be necessary --- app/assets/javascripts/misc.js.coffee | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 app/assets/javascripts/misc.js.coffee diff --git a/app/assets/javascripts/misc.js.coffee b/app/assets/javascripts/misc.js.coffee new file mode 100644 index 0000000..3a861c0 --- /dev/null +++ b/app/assets/javascripts/misc.js.coffee @@ -0,0 +1,38 @@ +$ -> + $('#logout').click -> + $(this).closest('form').submit() + + $('select').each (i, el) -> + $select = $(el) + + $select.wrap '
' + $select.on 'DOMSubtreeModified', (event) -> + $el = $(this) + $wrapper = $el.parent() + + if $el.is("[disabled]") + $wrapper.addClass 'disabled' + else + $wrapper.removeClass 'disabled' + + $select.trigger 'DOMSubtreeModified' + + $('a[href=#form_submit]').click -> + $(this).closest('form').submit() + return false + + $('select.autosubmit').change -> + $(this).closest('form').submit() + + $('#notification').delay(3000).fadeOut() + + $('#steam-search a').click (event) -> + event.preventDefault() + + $search = $('#steam-search') + id = $search.data 'user-id' + + $search.html "

Searching...

" + + $.get "/api/v1/users/#{id}", (data) -> + $search.html "Steam Profile: #{data.steam.nickname}" \ No newline at end of file From 7bbb6441a9298c9e3e556e0eb43c398188dfc808 Mon Sep 17 00:00:00 2001 From: cblanc Date: Sat, 9 May 2015 16:20:51 +0100 Subject: [PATCH 16/76] Added shoutbox controller to perform client side validation --- app/assets/javascripts/shoutbox.js | 76 ++++++++++++++++++++++++++++++ app/views/shoutmsgs/_new.html.erb | 10 ++++ 2 files changed, 86 insertions(+) create mode 100644 app/assets/javascripts/shoutbox.js diff --git a/app/assets/javascripts/shoutbox.js b/app/assets/javascripts/shoutbox.js new file mode 100644 index 0000000..4d511d8 --- /dev/null +++ b/app/assets/javascripts/shoutbox.js @@ -0,0 +1,76 @@ +// Shoutbox Controller manages input validation on shoutmsg form + +function ShoutboxController (options) { + if (!(this instanceof ShoutboxController)) { + return new ShoutboxController(options); + } + this.options = options; + this.$context = options.context; + if (this.$context.length) { + this.init(options); + } else { + console.log("Unable to initialize shoutbox controller. No context provided"); + } + return this; +} + +// Initialise shoutbox state +ShoutboxController.prototype.init = function (options) { + var self = this; + self.$input = self.$context.find(".shout_input"); + self.$button = self.$context.find('input[type="submit"]'); + self.$messageBox = null; + self.$input.change(function () { + if (self.$input.val().length > 100) { + self.disableShoutbox(); + } else { + self.enableShoutbox(); + } + }); + return self; +}; + +// Displays a message if `message` present, otherwise removes message elemt +ShoutboxController.prototype.writeMessage = function (message) { + if (message === undefined) return this.removeMessageBox(); + this.createMessageBox().html(message); + return this; +}; + +// Adds message box to DOM and cache +ShoutboxController.prototype.createMessageBox = function () { + if (this.$messageBox) return this.$messageBox; + this.$messageBox = $("

", {class: "shout-warning"}).appendTo(this.$context.find(".fields")); + return this.$messageBox; +}; + +// Removes message box from DOM and cache +ShoutboxController.prototype.removeMessageBox = function () { + if (this.$messageBox) { + this.$messageBox.remove(); + this.$messageBox = null; + } + return this; +}; + +// Returns true if button is disabled +ShoutboxController.prototype.isDisabled = function () { + return this.$button.prop("disabled") === true; +}; + +// Disables Input Button +ShoutboxController.prototype.disableShoutbox = function () { + var chars = this.$input.val().length; + this.writeMessage(["Shout message length exceeded (",chars,"/100)"].join("")); + this.$button.prop("disabled", true); +}; + +// Removes any warnings and enableds shoutbox submit +ShoutboxController.prototype.enableShoutbox = function () { + if (!this.$button.prop("disabled")) { + return this; + } + // Remove any warnings + this.writeMessage(); + this.$button.prop("disabled", false); +}; \ No newline at end of file diff --git a/app/views/shoutmsgs/_new.html.erb b/app/views/shoutmsgs/_new.html.erb index 25907da..523b076 100644 --- a/app/views/shoutmsgs/_new.html.erb +++ b/app/views/shoutmsgs/_new.html.erb @@ -17,3 +17,13 @@ <% end %> <% end %> <% end %> + + \ No newline at end of file From 4af732562079826ca9c58b5f9ec80d23f3215df3 Mon Sep 17 00:00:00 2001 From: cblanc Date: Sat, 9 May 2015 16:21:18 +0100 Subject: [PATCH 17/76] Added necessary factory methods to test shoutbox --- spec/factories/category.rb | 8 ++++++++ spec/factories/gather.rb | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 spec/factories/gather.rb diff --git a/spec/factories/category.rb b/spec/factories/category.rb index 5578a38..14dd5ef 100644 --- a/spec/factories/category.rb +++ b/spec/factories/category.rb @@ -3,4 +3,12 @@ FactoryGirl.define do sequence(:name) { |n| "Category #{n}" } sequence(:sort) { |n| n } end + + trait :news do + domain Category::DOMAIN_NEWS + end + + trait :game do + domain Category::DOMAIN_GAMES + end end \ No newline at end of file diff --git a/spec/factories/gather.rb b/spec/factories/gather.rb new file mode 100644 index 0000000..a7b1d0a --- /dev/null +++ b/spec/factories/gather.rb @@ -0,0 +1,13 @@ +FactoryGirl.define do + factory :gather do + association :category, factory: [:category, :game] + end + + trait :running do + status Gather::STATE_RUNNING + end + + trait :picking do + status Gather::STATE_PICKING + end +end From 5cdae9ea64842d9cc02fe9569ffaef35f9696e7e Mon Sep 17 00:00:00 2001 From: cblanc Date: Sat, 9 May 2015 16:21:48 +0100 Subject: [PATCH 18/76] Added test for client side shoutbox validation --- spec/features/gathers/gathers_spec.rb | 37 +++++++++++++++++++++++++ spec/features/shoutbox/shoutbox_spec.rb | 11 ++++++++ 2 files changed, 48 insertions(+) create mode 100644 spec/features/gathers/gathers_spec.rb diff --git a/spec/features/gathers/gathers_spec.rb b/spec/features/gathers/gathers_spec.rb new file mode 100644 index 0000000..71026b3 --- /dev/null +++ b/spec/features/gathers/gathers_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +feature 'Gathers', js: true do + let!(:user) { create :user } + let!(:gather) { create :gather, :running } + + feature 'Shoutbox' do + background do + sign_in_as user + end + + scenario 'create shout' do + visit gather_path(gather) + shout = rand(100000).to_s + fill_in "shout_Gather_#{gather.id}_text", with: shout + click_button 'Shout!' + expect(page).to have_content(shout) + end + + scenario 'enter more than 100 characters' do + valid_shout = 100.times.map { "a" }.join + invalid_shout = 101.times.map { "a" }.join + visit gather_path(gather) + expect(page).to_not have_content("Shout message length exceeded") + fill_in "shout_Gather_#{gather.id}_text", with: invalid_shout + expect(page).to have_content("Shout message length exceeded") + fill_in "shout_Gather_#{gather.id}_text", with: valid_shout + expect(page).to_not have_content("Shout message length exceeded") + end + + scenario 'creating shout while banned' do + Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username + visit root_path + expect(find("#sidebar")).to have_content "You have been muted." + end + end +end \ No newline at end of file diff --git a/spec/features/shoutbox/shoutbox_spec.rb b/spec/features/shoutbox/shoutbox_spec.rb index dec6542..a138a97 100644 --- a/spec/features/shoutbox/shoutbox_spec.rb +++ b/spec/features/shoutbox/shoutbox_spec.rb @@ -15,6 +15,17 @@ feature 'Shoutbox', js: true do expect(page).to have_content(shout) end + scenario 'enter more than 100 characters' do + valid_shout = 100.times.map { "a" }.join + invalid_shout = 101.times.map { "a" }.join + visit root_path + expect(page).to_not have_content("Shout message length exceeded") + fill_in 'shoutbox_text', with: invalid_shout + expect(page).to have_content("Shout message length exceeded") + fill_in 'shoutbox_text', with: valid_shout + expect(page).to_not have_content("Shout message length exceeded") + end + scenario 'creating shout while banned' do Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username visit root_path From a97e310528d9ffa91286063c07f4f0fec0a283e7 Mon Sep 17 00:00:00 2001 From: cblanc Date: Sat, 9 May 2015 16:36:50 +0100 Subject: [PATCH 19/76] Listen on both keyup and change events --- app/assets/javascripts/shoutbox.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/shoutbox.js b/app/assets/javascripts/shoutbox.js index 4d511d8..447f966 100644 --- a/app/assets/javascripts/shoutbox.js +++ b/app/assets/javascripts/shoutbox.js @@ -20,7 +20,7 @@ ShoutboxController.prototype.init = function (options) { self.$input = self.$context.find(".shout_input"); self.$button = self.$context.find('input[type="submit"]'); self.$messageBox = null; - self.$input.change(function () { + self.$input.bind("keyup change", function () { if (self.$input.val().length > 100) { self.disableShoutbox(); } else { @@ -61,7 +61,7 @@ ShoutboxController.prototype.isDisabled = function () { // Disables Input Button ShoutboxController.prototype.disableShoutbox = function () { var chars = this.$input.val().length; - this.writeMessage(["Shout message length exceeded (",chars,"/100)"].join("")); + this.writeMessage(["Maximum shout length exceeded (",chars,"/100)"].join("")); this.$button.prop("disabled", true); }; From 28269995205f7b44a488c4a07f70e91e149a8bfa Mon Sep 17 00:00:00 2001 From: cblanc Date: Sat, 9 May 2015 16:37:00 +0100 Subject: [PATCH 20/76] Changed wording on warning message --- spec/features/gathers/gathers_spec.rb | 6 +++--- spec/features/shoutbox/shoutbox_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/features/gathers/gathers_spec.rb b/spec/features/gathers/gathers_spec.rb index 71026b3..cdb8f8a 100644 --- a/spec/features/gathers/gathers_spec.rb +++ b/spec/features/gathers/gathers_spec.rb @@ -21,11 +21,11 @@ feature 'Gathers', js: true do valid_shout = 100.times.map { "a" }.join invalid_shout = 101.times.map { "a" }.join visit gather_path(gather) - expect(page).to_not have_content("Shout message length exceeded") + expect(page).to_not have_content("Maximum shout length exceeded") fill_in "shout_Gather_#{gather.id}_text", with: invalid_shout - expect(page).to have_content("Shout message length exceeded") + expect(page).to have_content("Maximum shout length exceeded") fill_in "shout_Gather_#{gather.id}_text", with: valid_shout - expect(page).to_not have_content("Shout message length exceeded") + expect(page).to_not have_content("Maximum shout length exceeded") end scenario 'creating shout while banned' do diff --git a/spec/features/shoutbox/shoutbox_spec.rb b/spec/features/shoutbox/shoutbox_spec.rb index a138a97..5a40b6e 100644 --- a/spec/features/shoutbox/shoutbox_spec.rb +++ b/spec/features/shoutbox/shoutbox_spec.rb @@ -19,11 +19,11 @@ feature 'Shoutbox', js: true do valid_shout = 100.times.map { "a" }.join invalid_shout = 101.times.map { "a" }.join visit root_path - expect(page).to_not have_content("Shout message length exceeded") + expect(page).to_not have_content("Maximum shout length exceeded") fill_in 'shoutbox_text', with: invalid_shout - expect(page).to have_content("Shout message length exceeded") + expect(page).to have_content("Maximum shout length exceeded") fill_in 'shoutbox_text', with: valid_shout - expect(page).to_not have_content("Shout message length exceeded") + expect(page).to_not have_content("Maximum shout length exceeded") end scenario 'creating shout while banned' do From 52ba336572c147ae982f2ab28f01997f2ad8a6ab Mon Sep 17 00:00:00 2001 From: cblanc Date: Sat, 9 May 2015 16:43:02 +0100 Subject: [PATCH 21/76] Cleanup --- app/views/shoutmsgs/_new.html.erb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/shoutmsgs/_new.html.erb b/app/views/shoutmsgs/_new.html.erb index 523b076..a424897 100644 --- a/app/views/shoutmsgs/_new.html.erb +++ b/app/views/shoutmsgs/_new.html.erb @@ -19,10 +19,8 @@ <% end %>