require "spec_helper" module Expressive describe TopLevel do describe "#to_hash" do it "return only the hash data" do @scope = TopLevel.new @scope["hello"] = "world" @scope.to_hash.should eql({"hello" => "world"}) end end end describe ExtendedValue do it "sets the multiple values of a ExtendedValue" do @scope = TopLevel.new @owned_by_ext_value = ExtendedValue.new(:x_owned_by, @scope) @owned_by_ext_value.setter = Proc.new do |value, scope| scope["owned_by_id"] = value.id scope["owned_by_type"] = value.class.to_s end @scope["x_owned_by"] = mock(:current_user, id: 1) @scope["owned_by_id"].should eql 1 @scope["owned_by_type"].should eql "RSpec::Mocks::Mock" @current_state_ext_value = ExtendedValue.new(:x_current_state, @scope) @current_state_ext_value.setter = Proc.new do |value, scope| scope["current_state"] = value.state scope["current_state_id"] = value.id end @scope["x_current_state"] = mock(:some_state, id: 1, state: "Pending") @scope["current_state_id"].should eql 1 @scope["current_state"].should eql "Pending" end it "add values to a Set construct" do @scope = TopLevel.new @participating_teams_ext_value = ExtendedValue.new(:x_participating_teams, @scope) @participating_teams_ext_value.adder = Proc.new do |value, scope| scope["participating_teams"] << value.id unless scope["participating_teams"].include?(value.id) end @scope["participating_teams"] = [1] @scope["x_participating_teams"] << mock(:some_team, id: 2, display_name: "The B-Team") @scope["x_participating_teams"] << mock(:some_team, id: 2, display_name: "The B-Team") @scope["participating_teams"].should =~ [1,2] end end end