From ede6f4fd460f3babb631e3ffcb1fffca20e2d9e6 Mon Sep 17 00:00:00 2001 From: Tobias Bohwalli Date: Sat, 12 Apr 2014 14:47:56 +0200 Subject: [PATCH] Update for Spree 2.1x and Rails 4 --- Gemfile | 4 ++-- README.md | 6 +++--- .../spree/admin/question_categories_controller.rb | 5 +++++ app/controllers/spree/faqs_controller.rb | 2 +- app/models/spree/question.rb | 1 - app/models/spree/question_category.rb | 1 - {script => bin}/rails | 0 .../admin/question_categories_controller_spec.rb | 13 +++++++++++++ spec/models/question_category_spec.rb | 6 ------ spec/models/question_spec.rb | 6 ------ spree_faq.gemspec | 6 +++--- 11 files changed, 27 insertions(+), 23 deletions(-) rename {script => bin}/rails (100%) diff --git a/Gemfile b/Gemfile index 33a00a9..703107d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -gem 'spree', github: 'spree/spree', branch: '2-0-stable' -gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-0-stable' +gem 'spree', github: 'spree/spree', branch: '2-1-stable' +gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable' gemspec diff --git a/README.md b/README.md index 3b340b6..c81033b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Spree Frequently Asked Question -[![Build Status](https://travis-ci.org/futhr/spree-faq.png?branch=2-0-stable)](https://travis-ci.org/futhr/spree-faq) -[![Coverage Status](https://coveralls.io/repos/futhr/spree-faq/badge.png?branch=2-0-stable)](https://coveralls.io/r/futhr/spree-faq) +[![Build Status](https://travis-ci.org/futhr/spree-faq.png?branch=2-1-stable)](https://travis-ci.org/futhr/spree-faq) +[![Coverage Status](https://coveralls.io/repos/futhr/spree-faq/badge.png?branch=2-1-stable)](https://coveralls.io/r/futhr/spree-faq) [![Code Climate](https://codeclimate.com/github/futhr/spree-faq.png)](https://codeclimate.com/github/futhr/spree-faq) [![Gem Version](https://badge.fury.io/rb/spree-faq.png)](http://badge.fury.io/rb/spree-faq) @@ -12,7 +12,7 @@ An Spree Commerce extension for managing FAQs. Add to your `Gemfile`: ```ruby -gem 'spree_faq', '~> 2.0.0' +gem 'spree_faq', '~> 2.1.0' ``` Then run from the command line: diff --git a/app/controllers/spree/admin/question_categories_controller.rb b/app/controllers/spree/admin/question_categories_controller.rb index ce36bd7..5beaaf1 100644 --- a/app/controllers/spree/admin/question_categories_controller.rb +++ b/app/controllers/spree/admin/question_categories_controller.rb @@ -8,6 +8,11 @@ class QuestionCategoriesController < ResourceController def question_category @question_category ||= @object end + + def question_category_params + params.require(:question_category).permit(:questions_attributes, :question, :answer, + question: [:question_category_id, :question, :answer]) + end end end end diff --git a/app/controllers/spree/faqs_controller.rb b/app/controllers/spree/faqs_controller.rb index edf2b10..64c7470 100644 --- a/app/controllers/spree/faqs_controller.rb +++ b/app/controllers/spree/faqs_controller.rb @@ -3,7 +3,7 @@ class FaqsController < StoreController helper 'spree/products' def index - @categories = QuestionCategory.all(include: :questions) + @categories = QuestionCategory.includes(:questions).load end def default_title diff --git a/app/models/spree/question.rb b/app/models/spree/question.rb index 4c6a47e..ba80f05 100644 --- a/app/models/spree/question.rb +++ b/app/models/spree/question.rb @@ -3,5 +3,4 @@ class Spree::Question < ActiveRecord::Base belongs_to :question_category, class_name: 'Spree::QuestionCategory' validates :question_category_id, :question, :answer, presence: true - attr_accessible :question, :answer, :question_category_id, :question_category end diff --git a/app/models/spree/question_category.rb b/app/models/spree/question_category.rb index 9c0be1f..5aecbfc 100644 --- a/app/models/spree/question_category.rb +++ b/app/models/spree/question_category.rb @@ -5,5 +5,4 @@ class Spree::QuestionCategory < ActiveRecord::Base validates :name, presence: true validates :name, uniqueness: { case_sensitive: false } accepts_nested_attributes_for :questions, allow_destroy: true - attr_accessible :name, :questions_attributes, :question, :answer end diff --git a/script/rails b/bin/rails similarity index 100% rename from script/rails rename to bin/rails diff --git a/spec/controllers/admin/question_categories_controller_spec.rb b/spec/controllers/admin/question_categories_controller_spec.rb index 65fe92e..b213586 100644 --- a/spec/controllers/admin/question_categories_controller_spec.rb +++ b/spec/controllers/admin/question_categories_controller_spec.rb @@ -64,4 +64,17 @@ expect { spree_delete :destroy }.to raise_error end end + + context 'permitted attributes' do + let(:permitted_attributes) do + [:questions_attributes, :question, :answer, + question: [:question_category_id, :question, :answer]] + end + + specify do + controller.params = { question_category: attributes } + controller.params.require(:question_category).should_receive(:permit).with(*permitted_attributes) + controller.send :question_category_params + end + end end diff --git a/spec/models/question_category_spec.rb b/spec/models/question_category_spec.rb index 7b4ce16..e612073 100644 --- a/spec/models/question_category_spec.rb +++ b/spec/models/question_category_spec.rb @@ -28,12 +28,6 @@ it { should accept_nested_attributes_for(:questions) } end - context 'mass assignment' do - %w(name questions_attributes question answer).each do |column| - it { should allow_mass_assignment_of(column.to_sym) } - end - end - context 'acts as list' do subject { create(:question_category) } diff --git a/spec/models/question_spec.rb b/spec/models/question_spec.rb index 26adb85..02997aa 100644 --- a/spec/models/question_spec.rb +++ b/spec/models/question_spec.rb @@ -50,12 +50,6 @@ end end - context 'mass assignment' do - %w(question answer question_category_id question_category).each do |column| - it { should allow_mass_assignment_of(column.to_sym) } - end - end - context 'acts as list' do before do diff --git a/spree_faq.gemspec b/spree_faq.gemspec index 12dc249..dd4b16a 100644 --- a/spree_faq.gemspec +++ b/spree_faq.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |s| s.has_rdoc = false - s.add_runtime_dependency 'spree_core', '~> 2.0.0' + s.add_runtime_dependency 'spree_core', '~> 2.1.0' s.add_development_dependency 'rspec-rails', '~> 2.14' s.add_development_dependency 'capybara', '~> 2.2.1' @@ -35,8 +35,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'simplecov', '~> 0.7.1' s.add_development_dependency 'database_cleaner', '~> 1.2.0' s.add_development_dependency 'i18n-spec', '~> 0.4.1' - s.add_development_dependency 'coffee-rails', '~> 3.2.2' - s.add_development_dependency 'sass-rails', '~> 3.2.6' + s.add_development_dependency 'coffee-rails', '~> 4.0.0' + s.add_development_dependency 'sass-rails', '~> 4.0.0' s.add_development_dependency 'ffaker', '>= 1.24.0' s.add_development_dependency 'guard-rspec', '>= 4.2.0' s.add_development_dependency 'launchy', '>= 2.4.0'