From f3282e33a352007b88769de7bcb20d78d5497db7 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Wed, 15 May 2013 15:19:41 -0400 Subject: [PATCH] Add tabs to category create/edit modal. Categories can have a default auto-close setting that applies to all new topics created in the category. Add rspec-given and write some integration tests. Tests for topic auto-close with category default --- Gemfile | 1 + Gemfile.lock | 5 + .../javascripts/discourse/models/category.js | 3 +- .../javascripts/discourse/models/composer.js | 8 +- .../templates/auto_close_form.js.handlebars | 6 + .../templates/composer.js.handlebars | 7 +- .../templates/modal/auto_close.js.handlebars | 7 +- .../modal/edit_category.js.handlebars | 105 +++++++++++------- .../discourse/views/auto_close_form_view.js | 21 ++++ .../views/modal/edit_category_view.js | 27 ++++- .../stylesheets/application/modal.css.scss | 16 ++- app/controllers/categories_controller.rb | 2 +- app/models/topic.rb | 6 + app/serializers/category_serializer.rb | 2 +- config/locales/client.en.yml | 3 + ...93551_add_auto_close_days_to_categories.rb | 5 + lib/jobs.rb | 23 ++-- lib/jobs/close_topic.rb | 2 +- spec/components/jobs/close_topic_spec.rb | 41 ++++--- spec/integration/.gitkeep | 0 spec/integration/topic_auto_close_spec.rb | 85 ++++++++++++++ spec/models/topic_spec.rb | 21 +++- 22 files changed, 298 insertions(+), 98 deletions(-) create mode 100644 app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars create mode 100644 app/assets/javascripts/discourse/views/auto_close_form_view.js create mode 100644 db/migrate/20130515193551_add_auto_close_days_to_categories.rb create mode 100644 spec/integration/.gitkeep create mode 100644 spec/integration/topic_auto_close_spec.rb diff --git a/Gemfile b/Gemfile index 3b5625afd..8c546ed4e 100644 --- a/Gemfile +++ b/Gemfile @@ -108,6 +108,7 @@ group :test, :development do gem 'simplecov', require: false gem 'terminal-notifier-guard', require: false gem 'timecop' + gem 'rspec-given' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index c2e7346a8..c35b94be2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -371,6 +371,9 @@ GEM rspec-core (2.13.1) rspec-expectations (2.13.0) diff-lcs (>= 1.1.3, < 2.0) + rspec-given (2.4.1) + rspec (>= 2.11) + sorcerer (>= 0.3.7) rspec-mocks (2.13.1) rspec-rails (2.13.0) actionpack (>= 3.0) @@ -416,6 +419,7 @@ GEM temple (~> 0.6.3) tilt (~> 1.3.3) slop (3.4.4) + sorcerer (0.3.10) spork (0.9.2) temple (0.6.4) terminal-notifier-guard (1.5.3) @@ -511,6 +515,7 @@ DEPENDENCIES redis-rails rest-client rinku + rspec-given rspec-rails sanitize sass diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index 4044a41e5..24db481ed 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -45,7 +45,8 @@ Discourse.Category = Discourse.Model.extend({ text_color: this.get('text_color'), hotness: this.get('hotness'), secure: this.get('secure'), - group_names: this.get('groups').join(",") + group_names: this.get('groups').join(","), + auto_close_days: this.get('auto_close_days') }, type: this.get('id') ? 'PUT' : 'POST' }); diff --git a/app/assets/javascripts/discourse/models/composer.js b/app/assets/javascripts/discourse/models/composer.js index 101cb883d..e4d7d5159 100644 --- a/app/assets/javascripts/discourse/models/composer.js +++ b/app/assets/javascripts/discourse/models/composer.js @@ -538,13 +538,7 @@ Discourse.Composer = Discourse.Model.extend({ var reply = this.get('reply') || ""; while (Discourse.BBCode.QUOTE_REGEXP.test(reply)) { reply = reply.replace(Discourse.BBCode.QUOTE_REGEXP, ""); } return reply.replace(/\s+/img, " ").trim().length; - }.property('reply'), - - autoCloseChanged: function() { - if( this.get('auto_close_days') && this.get('auto_close_days').length > 0 ) { - this.set('auto_close_days', this.get('auto_close_days').replace(/[^\d]/g, '') ) - } - }.observes('auto_close_days') + }.property('reply') }); diff --git a/app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars b/app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars new file mode 100644 index 000000000..eff55b4f0 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/auto_close_form.js.handlebars @@ -0,0 +1,6 @@ +
+ + {{view.label}} + {{view Discourse.TextField valueBinding="view.autoCloseDays" maxlength="3"}} + {{i18n composer.auto_close_units}} +
diff --git a/app/assets/javascripts/discourse/templates/composer.js.handlebars b/app/assets/javascripts/discourse/templates/composer.js.handlebars index 70cdd2cdb..4150619b4 100644 --- a/app/assets/javascripts/discourse/templates/composer.js.handlebars +++ b/app/assets/javascripts/discourse/templates/composer.js.handlebars @@ -45,12 +45,7 @@
-
- - {{i18n composer.auto_close_label}} - {{view Discourse.TextField valueBinding="content.auto_close_days" maxlength="5"}} - {{i18n composer.auto_close_units}} -
+ {{view Discourse.AutoCloseFormView autoCloseDaysBinding="content.auto_close_days"}}
{{/if}} diff --git a/app/assets/javascripts/discourse/templates/modal/auto_close.js.handlebars b/app/assets/javascripts/discourse/templates/modal/auto_close.js.handlebars index dc3229eaa..c43ab6282 100644 --- a/app/assets/javascripts/discourse/templates/modal/auto_close.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/auto_close.js.handlebars @@ -1,11 +1,6 @@