Module: Ccls::Assertions::ClassMethods

Defined in:
lib/ccls_engine/assertions.rb

Instance Method Summary collapse

Instance Method Details

#assert_should_behave_like_a_hash(*args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ccls_engine/assertions.rb', line 37

def assert_should_behave_like_a_hash(*args)
	options = {
		:key => :key,
		:value => :description
	}
	options.update(args.extract_options!)

	assert_should_require_attribute( options[:key], options[:value] )
	assert_should_require_unique_attribute( options[:key], options[:value] )
	assert_should_require_attribute_length( options[:key], options[:value],
		:maximum => 250 )

	test "should find by key with ['string']" do
		object = create_object
		assert object.is_a?(model_name.constantize)
		found = (model_name.constantize)[object.key.to_s]
		assert found.is_a?(model_name.constantize)
		assert_equal object, found
	end

	test "should find by key with [:symbol]" do
		object = create_object
		assert object.is_a?(model_name.constantize)
		found = (model_name.constantize)[object.key.to_sym]
		assert found.is_a?(model_name.constantize)
		assert_equal object, found
	end

end

#assert_should_create_default_objectObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ccls_engine/assertions.rb', line 25

def assert_should_create_default_object
	#	It appears that model_name is a defined class method already in ...
	#	activesupport-####/lib/active_support/core_ext/module/model_naming.rb
	test "should create default #{model_name.sub(/Test$/,'').underscore}" do
		assert_difference( "#{model_name}.count", 1 ) do
			object = create_object
			assert !object.new_record?, 
				"#{object.errors.full_messages.to_sentence}"
		end
	end
end