rep 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -3,9 +3,9 @@ rvm:
3
3
  - "1.8.7"
4
4
  - "1.9.2"
5
5
  - "1.9.3"
6
- - jruby-18mode # JRuby in 1.8 mode
7
- - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-18mode
9
- - rbx-19mode
6
+ # - jruby-18mode # JRuby in 1.8 mode
7
+ # - jruby-19mode # JRuby in 1.9 mode
8
+ # - rbx-18mode
9
+ # - rbx-19mode
10
10
  # uncomment this line if your project needs to run something other than `rake`:
11
11
  # script: bundle exec rspec spec
data/lib/rep.rb CHANGED
@@ -56,6 +56,15 @@ module Rep
56
56
  include HashieSupport
57
57
  end
58
58
  end
59
+
60
+ # Translate for ActiveSupport, the jerk
61
+ if method(:delegate).arity == -1
62
+ def delegate(opts = {})
63
+ methods, object_name = opts.to_a.first
64
+ args = methods.concat([:to => object_name])
65
+ super(*args)
66
+ end
67
+ end
59
68
  }
60
69
  end
61
70
 
data/lib/rep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rep
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/lib/rep_test.rb CHANGED
@@ -70,7 +70,8 @@ describe Rep do
70
70
  fields [:one, :four] => :default
71
71
  fields [:one, :two, :three] => :superset
72
72
  end
73
- klass.all_json_fields.must_equal [:one, :four, :two, :three]
73
+ fields = klass.all_json_fields.map { |f| f.to_s }.sort
74
+ fields.must_equal [:one, :four, :two, :three].map { |f| f.to_s }.sort
74
75
  end
75
76
 
76
77
  it "should send fields to instance to make hash" do
@@ -127,12 +128,30 @@ describe Rep do
127
128
  klass = new_rep_class do
128
129
  initialize_with :hash
129
130
  fields :keys => :default
130
- forward :keys => :hash
131
+ def keys
132
+ hash.keys.map { |k| k.to_s }.sort
133
+ end
131
134
  end
132
135
  hashes = [{ :one => 1, :two => 2 },
133
136
  { :three => 3, :four => 4 },
134
137
  { :one => 1, :five => 5 }]
135
- hashes.map(&klass).to_json.must_equal '[{"keys":["one","two"]},{"keys":["three","four"]},{"keys":["one","five"]}]'
138
+ result = [{ "keys" => ["one", "two"] }, { "keys" => ["four", "three"] }, { "keys" => ["five", "one"] }]
139
+ JSON.parse(hashes.map(&klass).to_json).must_equal result
140
+ end
141
+
142
+ describe "forward" do
143
+ class Forwardtest
144
+ include Rep
145
+ attr_reader :target
146
+ def initialize
147
+ @target = "Hello, I am a string"
148
+ end
149
+ forward [:length] => :target
150
+ end
151
+
152
+ it "should forward (delegate)" do
153
+ assert_equal 20, Forwardtest.new.length
154
+ end
136
155
  end
137
156
 
138
157
  describe "shared" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: