From 1a17d485d172c9bea1060d4e088435abe5cf78bb Mon Sep 17 00:00:00 2001 From: Justin Windholtz Date: Sun, 19 Mar 2017 10:02:11 -0400 Subject: [PATCH] more test fixes --- Rakefile | 1 + app/helpers/cms/section_nodes_helper.rb | 2 +- app/models/cms/form.rb | 1 + lib/cms/behaviors/attaching.rb | 2 +- lib/cms/behaviors/dynamic_attributes.rb | 2 +- .../abstract/schema_statements.rb | 4 +- lib/command_line.rb | 2 +- spec/cms/email_message_spec.rb | 2 +- spec/cms/form_fields_spec.rb | 8 ++-- spec/cms/form_spec.rb | 2 +- spec/concerns/addressable_spec.rb | 15 ++++--- spec/minitest_helper.rb | 1 + test/dummy/db/schema.rb | 40 +++++++++---------- .../cms/sections_controller_test.rb | 4 +- test/minitest_helper.rb | 4 +- test/support/factory_helpers.rb | 2 +- test/test_helper.rb | 5 ++- 17 files changed, 53 insertions(+), 44 deletions(-) diff --git a/Rakefile b/Rakefile index 1d0892159..ec13f40c5 100644 --- a/Rakefile +++ b/Rakefile @@ -91,6 +91,7 @@ def run_tests(tests_to_run) Rake::Task[task].invoke nil rescue => e + puts e {:task => task, :exception => e} end end.compact diff --git a/app/helpers/cms/section_nodes_helper.rb b/app/helpers/cms/section_nodes_helper.rb index 3b05dea42..4d9e81950 100644 --- a/app/helpers/cms/section_nodes_helper.rb +++ b/app/helpers/cms/section_nodes_helper.rb @@ -21,7 +21,7 @@ def add_link_path_data(section_node, parent_section_node) def add_section_path_data(section_node, parent_section_node) section = figure_out_target_section(parent_section_node, section_node) - new_section_path(section_id: section) + new_section_path(section_id: section.id) end # When sitemap initially renders, we only want to show first level. diff --git a/app/models/cms/form.rb b/app/models/cms/form.rb index e9f1dee1c..10b84dfd4 100644 --- a/app/models/cms/form.rb +++ b/app/models/cms/form.rb @@ -26,6 +26,7 @@ def field(name) end def required?(name) + name = name.to_s if name.class==Symbol field = field(name) field ? field.required? : false end diff --git a/lib/cms/behaviors/attaching.rb b/lib/cms/behaviors/attaching.rb index 05ca63db8..634e32ffe 100644 --- a/lib/cms/behaviors/attaching.rb +++ b/lib/cms/behaviors/attaching.rb @@ -219,7 +219,7 @@ def attachment_names end def after_publish - attachments.each &:publish + attachments.each(&:publish) end # Locates the attachment with a given name diff --git a/lib/cms/behaviors/dynamic_attributes.rb b/lib/cms/behaviors/dynamic_attributes.rb index c73195d44..bf13c2bb7 100644 --- a/lib/cms/behaviors/dynamic_attributes.rb +++ b/lib/cms/behaviors/dynamic_attributes.rb @@ -233,7 +233,7 @@ def assign_attributes(new_attributes, options = {}) return unless new_attributes attributes = new_attributes.stringify_keys - role = options[:as] || :default + options[:as] || :default multi_parameter_attributes = [] diff --git a/lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb b/lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb index f209e476c..8c5ade664 100644 --- a/lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb +++ b/lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb @@ -38,7 +38,7 @@ def create_content_table(table_name, options={}, &block) td.boolean :archived, :default => false td.integer :created_by_id td.integer :updated_by_id - td.timestamps unless column_exists?(table_name.to_sym, :created_at) + td.timestamps null: false unless column_exists?(table_name.to_sym, :created_at) end if versioned @@ -54,7 +54,7 @@ def create_content_table(table_name, options={}, &block) vt.string :version_comment vt.integer :created_by_id vt.integer :updated_by_id - vt.timestamps unless column_exists?(table_name_versioned, :created_at) + vt.timestamps null: false unless column_exists?(table_name_versioned, :created_at) end end diff --git a/lib/command_line.rb b/lib/command_line.rb index f54fd4dbf..32c442140 100644 --- a/lib/command_line.rb +++ b/lib/command_line.rb @@ -29,7 +29,7 @@ def self.set_template(args) def self.template_dir current_file = File.expand_path(File.dirname(__FILE__)) gem_dir = File.join(current_file, "..") - template_dir = File.join(gem_dir, "templates") + File.join(gem_dir, "templates") end # Return the file for the given template. diff --git a/spec/cms/email_message_spec.rb b/spec/cms/email_message_spec.rb index a50fb53c2..1fb77f2c4 100644 --- a/spec/cms/email_message_spec.rb +++ b/spec/cms/email_message_spec.rb @@ -11,7 +11,7 @@ describe "#absolute_cms_url" do it "should return a url which points to the cms admin version of a page" do - Rails.configuration.cms.expects(:site_domain).retu rns('www.example.com') + Rails.configuration.cms.expects(:site_domain).returns('www.example.com') url = Cms::EmailMessage.absolute_cms_url("/some-path") url.must_equal "http://cms.example.com/some-path" end diff --git a/spec/cms/form_fields_spec.rb b/spec/cms/form_fields_spec.rb index dd504b59b..fbfcd9b95 100644 --- a/spec/cms/form_fields_spec.rb +++ b/spec/cms/form_fields_spec.rb @@ -1,5 +1,5 @@ require "minitest_helper" - +require 'mocha' describe Cms::FormField do describe '.permitted_params' do @@ -34,18 +34,18 @@ describe '#name' do it "should return a symbol that can be used as the name for inputs" do field = Cms::FormField.create!(label: 'Name') - field.name.must_equal :name + field.name.must_equal "name" end it "should underscore names" do field = Cms::FormField.create!(label: 'Full Name') - field.name.must_equal :full_name + field.name.must_equal "full_name" end it "should not change after being saved even when the label is changed" do field = Cms::FormField.create!(label: 'Name') field.update(label: 'Full Name') - field.name.must_equal :name + field.name.must_equal "name" end diff --git a/spec/cms/form_spec.rb b/spec/cms/form_spec.rb index 96dc92cae..1f896c00d 100644 --- a/spec/cms/form_spec.rb +++ b/spec/cms/form_spec.rb @@ -106,7 +106,7 @@ def form_with_fields(field_labels=[]) form.fields << Cms::FormField.new(label: 'Name') form.fields << Cms::FormField.new(label: 'Email') form.save! - form.field_names.must_equal [:name, :email] + form.field_names.must_equal ["name", "email"] end end diff --git a/spec/concerns/addressable_spec.rb b/spec/concerns/addressable_spec.rb index cff9f3d2c..838142b2f 100644 --- a/spec/concerns/addressable_spec.rb +++ b/spec/concerns/addressable_spec.rb @@ -71,6 +71,9 @@ def create_testing_table(name, &block) WannabeAddressable.expects(:has_one) WannabeAddressable.expects(:after_save) WannabeAddressable.expects(:after_validation) + puts "heres info" + puts WannabeAddressable.class + puts WannabeAddressable.to_yaml WannabeAddressable.is_addressable WannabeAddressable.new.must_respond_to :parent end @@ -132,7 +135,7 @@ class Dummy::OverrideSpecifiedTemplate < ActiveRecord::Base describe ".destroy" do it "should also delete the section node" do - add = IsAddressable.create(slug: "coke", parent_id: root_section) + add = IsAddressable.create(slug: "coke", parent_id: root_section.id) before = Cms::SectionNode.count add.destroy (Cms::SectionNode.count - before).must_equal -1 @@ -157,8 +160,8 @@ class Dummy::OverrideSpecifiedTemplate < ActiveRecord::Base end it "should be unique for each class" do - first = IsAddressable.create(slug: "first", parent_id: root_section) - duplicate = IsAddressable.create(slug: "first", parent_id: root_section) + first = IsAddressable.create(slug: "first", parent_id: root_section.id) + duplicate = IsAddressable.create(slug: "first", parent_id: root_section.id) duplicate.wont_be :valid? duplicate.section_node.errors[:slug].must_equal ["has already been taken"] @@ -188,7 +191,7 @@ class Dummy::OverrideSpecifiedTemplate < ActiveRecord::Base end it "should find content" do - content = IsAddressable.create(slug: "coke", parent_id: root_section) + content = IsAddressable.create(slug: "coke", parent_id: root_section.id) found = IsAddressable.with_slug("coke") found.wont_be_nil @@ -196,8 +199,8 @@ class Dummy::OverrideSpecifiedTemplate < ActiveRecord::Base end it "should find correct type" do - AnotherAddressable.create!(slug: "coke", parent_id: root_section) - content = IsAddressable.create(slug: "coke", parent_id: root_section) + AnotherAddressable.create!(slug: "coke", parent_id: root_section.id) + content = IsAddressable.create(slug: "coke", parent_id: root_section.id) found = IsAddressable.with_slug("coke") found.must_equal content diff --git a/spec/minitest_helper.rb b/spec/minitest_helper.rb index 01eca4e0c..47090f61c 100644 --- a/spec/minitest_helper.rb +++ b/spec/minitest_helper.rb @@ -4,6 +4,7 @@ require "minitest/spec" require "minitest/unit" + Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } require File.expand_path("../../test/factories/factories", __FILE__) require File.expand_path("../../test/factories/attachable_factories", __FILE__) diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 10c40766a..625ed5c07 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -60,8 +60,8 @@ t.string "version_comment", limit: 255 t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "cms_attachment_versions", ["original_record_id"], name: "index_cms_attachment_versions_on_original_record_id", using: :btree @@ -85,8 +85,8 @@ t.boolean "archived", default: false t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "cms_categories", force: :cascade do |t| @@ -187,8 +187,8 @@ t.string "version_comment", limit: 255 t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "cms_file_block_versions", ["original_record_id"], name: "index_cms_file_block_versions_on_original_record_id", using: :btree @@ -206,8 +206,8 @@ t.boolean "archived", default: false t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "cms_file_blocks", ["deleted"], name: "index_cms_file_blocks_on_deleted", using: :btree @@ -251,8 +251,8 @@ t.string "version_comment", limit: 255 t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "cms_forms", force: :cascade do |t| @@ -269,8 +269,8 @@ t.boolean "archived", default: false t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end create_table "cms_group_permissions", force: :cascade do |t| @@ -327,8 +327,8 @@ t.string "version_comment", limit: 255 t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "cms_html_block_versions", ["original_record_id"], name: "index_cms_html_block_versions_on_original_record_id", using: :btree @@ -344,8 +344,8 @@ t.boolean "archived", default: false t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "cms_html_blocks", ["deleted"], name: "index_cms_html_blocks_on_deleted", using: :btree @@ -418,8 +418,8 @@ t.string "version_comment", limit: 255 t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_index "cms_page_versions", ["original_record_id"], name: "index_cms_page_versions_on_original_record_id", using: :btree @@ -441,8 +441,8 @@ t.boolean "archived", default: false t.integer "created_by_id", limit: 4 t.integer "updated_by_id", limit: 4 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "latest_version", limit: 4 end diff --git a/test/functional/cms/sections_controller_test.rb b/test/functional/cms/sections_controller_test.rb index 242e12b98..4e44d4508 100644 --- a/test/functional/cms/sections_controller_test.rb +++ b/test/functional/cms/sections_controller_test.rb @@ -89,10 +89,10 @@ def test_new_permissions def test_create_permissions login_as(@user) - post :create, :section_id => @editable_section, section: {:name => "Another editable subsection"} + post :create, :section_id => @editable_section.id, section: {:name => "Another editable subsection"} assert_response :success - post :create, :section_id => @noneditable_section, section: {:name => "Another non-editable subsection"} + post :create, :section_id => @noneditable_section.id, section: {:name => "Another non-editable subsection"} assert_response 403 assert_template "cms/shared/access_denied" end diff --git a/test/minitest_helper.rb b/test/minitest_helper.rb index 3c20a36e0..59c54ad24 100644 --- a/test/minitest_helper.rb +++ b/test/minitest_helper.rb @@ -15,7 +15,6 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } require 'factories/factories' require 'factories/attachable_factories' - require 'minitest/reporters' MiniTest::Reporters.use! @@ -36,6 +35,9 @@ class Minitest::Spec include FactoryHelpers end +require 'mocha' + + #class MiniTest::Rails::ActiveSupport::TestCase # # # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. diff --git a/test/support/factory_helpers.rb b/test/support/factory_helpers.rb index 838c72ac3..f616c95f8 100644 --- a/test/support/factory_helpers.rb +++ b/test/support/factory_helpers.rb @@ -3,7 +3,7 @@ module FactoryHelpers def new_attachment(name="spreadsheet", path=nil) {"0" => { :data => mock_file, - :section_id => root_section, + :section_id => root_section.id, :data_file_path => path, :attachment_name => name}} end diff --git a/test/test_helper.rb b/test/test_helper.rb index e0c75cd93..ccf02ddd0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -8,7 +8,6 @@ require 'minitest/unit' # Load support files Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } - require 'mocha/setup' require 'action_view/test_case' @@ -25,10 +24,12 @@ require 'factories/attachable_factories' # Silence warnings (hopefully) primarily from HTML parsing in functional tests. -$VERBOSE = nil +#$VERBOSE = nil require 'support/engine_controller_hacks' + + class ActiveSupport::TestCase include FactoryGirl::Syntax::Methods