test/lib/rep_test.rb in rep-0.0.2 vs test/lib/rep_test.rb in rep-0.0.3

- old
+ new

@@ -68,11 +68,12 @@ it "should know all uniq fields" do klass = new_rep_class do fields [:one, :four] => :default fields [:one, :two, :three] => :superset end - klass.all_json_fields.must_equal [:one, :four, :two, :three] + fields = klass.all_json_fields.map { |f| f.to_s }.sort + fields.must_equal [:one, :four, :two, :three].map { |f| f.to_s }.sort end it "should send fields to instance to make hash" do klass = new_rep_class do fields [:one, :two, :three] => :default @@ -125,15 +126,33 @@ it "should do symbol to instance craziness" do klass = new_rep_class do initialize_with :hash fields :keys => :default - forward :keys => :hash + def keys + hash.keys.map { |k| k.to_s }.sort + end end hashes = [{ :one => 1, :two => 2 }, { :three => 3, :four => 4 }, { :one => 1, :five => 5 }] - hashes.map(&klass).to_json.must_equal '[{"keys":["one","two"]},{"keys":["three","four"]},{"keys":["one","five"]}]' + result = [{ "keys" => ["one", "two"] }, { "keys" => ["four", "three"] }, { "keys" => ["five", "one"] }] + JSON.parse(hashes.map(&klass).to_json).must_equal result + end + + describe "forward" do + class Forwardtest + include Rep + attr_reader :target + def initialize + @target = "Hello, I am a string" + end + forward [:length] => :target + end + + it "should forward (delegate)" do + assert_equal 20, Forwardtest.new.length + end end describe "shared" do User = Struct.new(:name, :age)