Skip to content

Commit

Permalink
more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwohiou committed Mar 19, 2017
1 parent 7d03cfd commit 1a17d48
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 44 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/cms/section_nodes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions app/models/cms/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cms/behaviors/attaching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cms/behaviors/dynamic_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion spec/cms/email_message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/cms/form_fields_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "minitest_helper"

require 'mocha'
describe Cms::FormField do

describe '.permitted_params' do
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion spec/cms/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 9 additions & 6 deletions spec/concerns/addressable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"]
Expand Down Expand Up @@ -188,16 +191,16 @@ 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
found.must_equal content
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

Expand Down
1 change: 1 addition & 0 deletions spec/minitest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
40 changes: 20 additions & 20 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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|
Expand All @@ -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|
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/functional/cms/sections_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/minitest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/support/factory_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
Expand Down

0 comments on commit 1a17d48

Please sign in to comment.