Sha256: 75b510b9e6ef8b0da30a429b7178e45c3274afa0b23084678c39775241f3ae0a

Contents?: true

Size: 1.4 KB

Versions: 35

Compression:

Stored size: 1.4 KB

Contents

require File.dirname(__FILE__) + '/spec_helper'

module ViewSpec
	
	TestValues = {
		date: Date.today,
		number: 27,
		int: 356192,
		float: 72.362517,
		bool: true
	}
	
	TestData = TestValues.inject({}){|acc,(k,v)| acc["a_#{k}".to_sym] = v; acc }
	
	class ViewedObject < RedisObject
		
		named_view :bare, :a_float, :a_bool
		named_view :aggregated, :a_float, :a_bool, :aggregate
		named_view :aggregated_only, :method => :aggregate
		named_view :proc, {:lambda => Proc.new {|o| o.get(:a_bool) } }, :aggregate
		named_view :hashy, {:hesher => :a_number }, :aggregate
		
		TestValues.keys.each do |type|
			send(type.to_sym,"a_#{type}".to_sym)
		end
		
		def aggregate
			a_number + a_int
		end
		
	end
	
	describe Seabright::Views do
		
		before do
			RedisObject.store.flushdb
			@obj = ViewedObject.create(TestData)
		end
		
		it "generates view" do
			
			@obj.view_as_hash(:bare).should be_a(Hash)
			@obj.view_as_json(:bare).should be_a(String)
			
		end
		
		it "generates mthod-only view" do
			
			@obj.view_as_hash(:aggregated_only).should be_a(Fixnum)
			
		end
		
		it "views methods properly" do
			
			@obj.view_as_hash(:aggregated)["aggregate"].should eq(TestData[:a_number] + TestData[:a_int])
			
		end
		
		it "executes procs within view" do
			
			@obj.view_as_json(:proc).should be_a(String)
			
		end
		
		it "generates hashes within view" do
			
			@obj.view_as_hash(:hashy).should be_a(Hash)
			
		end
		
	end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
redis_object-1.5.1 spec/views_spec.rb
redis_object-1.5.0 spec/views_spec.rb
redis_object-1.4.9 spec/views_spec.rb
redis_object-1.4.8 spec/views_spec.rb
redis_object-1.4.7 spec/views_spec.rb
redis_object-1.4.6 spec/views_spec.rb
redis_object-1.4.5 spec/views_spec.rb
redis_object-1.4.3 spec/views_spec.rb
redis_object-1.4.2 spec/views_spec.rb
redis_object-1.4.1 spec/views_spec.rb
redis_object-1.4.0 spec/views_spec.rb
redis_object-1.3.9 spec/views_spec.rb
redis_object-1.3.8 spec/views_spec.rb
redis_object-1.3.7 spec/views_spec.rb
redis_object-1.3.6 spec/views_spec.rb
redis_object-1.3.5 spec/views_spec.rb
redis_object-1.3.4 spec/views_spec.rb
redis_object-1.3.3 spec/views_spec.rb
redis_object-1.3.2 spec/views_spec.rb
redis_object-1.3.1b spec/views_spec.rb