Sha256: 47d039acb4a92f33ab384b6a07fc8fdb92c5a0336020e52249be45dba951bca0

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

##
# Allows testing of multiple columns in a database for a single trait
#
module SpecStacker

	##
	#it should test value for action
	#+value+:: symbol for a column name
	#+action+:: symbol for an action (eg. +validate_presence_of+)
	def it_should value, action
		it { should send(action, value) }
	end

	##
	#test attributes with action
	#+attributes+:: array of symbols of columns names
	#+action+:: the action to check, see it_should
	def should_all attributes, action
		attributes.each { |k| it_should(k, action) }
	end

	##
	#test if attributes are present
	#+attributes+:: array of symbols of column names
	def should_all_be_present attributes
		should_all attributes, :validate_presence_of
	end

	##
	#test if all attributes have_and_belong_to_many
	#+attributes+:: array of symbols of attributes
	#
	#the normal identifier is too long.
	def should_all_join attributes
		should_all attributes, :have_and_belong_to_many
	end

	##
	#test if attributes belong_to
	#+attribtes+:: array of symbols of attributes
	def should_all_belong_to attributes
		should_all attributes, :belong_to
	end

	##
	#test if model has_many attributes
	#+attributes+:: array of symbols of attributes
	def should_all_have_many attributes
		should_all attributes, :have_many
	end

	##
	#test for nested attributes
	#+attributes+:: array of symbols of attributes
	def should_all_nest attributes
		should_all attributes, :accept_nested_attributes_for
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_model_stacker-0.0.7 lib/rails_model_stacker/spec_stacker.rb
rails_model_stacker-0.0.6 lib/rails_model_stacker/spec_stacker.rb
rails_model_stacker-0.0.5 lib/rails_model_stacker/spec_stacker.rb