poncho 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ require 'minitest/autorun'
2
+ require 'rack/mock'
3
+ require 'poncho'
4
+ require 'json'
5
+
6
+ class TestResource < MiniTest::Unit::TestCase
7
+ class Fuzzy
8
+ def initialize(attrs = {})
9
+ attrs.each do |key, value|
10
+ self.class.send :attr_accessor, key
11
+ self.send("#{key}=", value)
12
+ end
13
+ end
14
+ end
15
+
16
+ def test_resource_params
17
+ resource = Class.new(Poncho::Resource) do
18
+ param :amount, :type => :integer
19
+ end
20
+
21
+ result = resource.new(Fuzzy.new(:amount => 1))
22
+ assert_equal({:amount => 1}, result.as_json)
23
+ end
24
+
25
+ def test_resource_validation
26
+ resource = Class.new(Poncho::Resource) do
27
+ param :amount, :type => :integer
28
+ end
29
+
30
+ result = resource.new(Fuzzy.new(:amount => nil))
31
+ assert result.valid?
32
+
33
+ result = resource.new(Fuzzy.new(:amount => 1))
34
+ assert result.valid?
35
+
36
+ result = resource.new(Fuzzy.new(:amount => 's'))
37
+ assert !result.valid?
38
+ end
39
+
40
+ def test_resource_conversion
41
+ resource = Class.new(Poncho::Resource) do
42
+ param :amount, :type => :integer
43
+
44
+ def amount
45
+ super * 10
46
+ end
47
+ end
48
+
49
+ result = resource.new(Fuzzy.new(:amount => 2))
50
+ assert_equal 20, result.amount
51
+ assert_equal({:amount => 20}, result.as_json)
52
+ end
53
+
54
+ def test_sub_resources
55
+ card_resource = Class.new(Poncho::Resource) do
56
+ param :number
57
+
58
+ def number
59
+ super[-4..-1]
60
+ end
61
+ end
62
+
63
+ resource = Class.new(Poncho::Resource) do
64
+ param :card, :resource => card_resource
65
+ end
66
+
67
+ card = Fuzzy.new(:number => '4242 4242 4242 4242')
68
+ result = resource.new(Fuzzy.new(:card => card))
69
+ assert_equal({:card => {:number => '4242'}}.to_json, result.to_json)
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poncho
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex MacCaw
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Poncho is an API to build REST APIs with a convenient DSL.
15
+ email:
16
+ - alex@stripe.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - examples/app.rb
27
+ - lib/poncho.rb
28
+ - lib/poncho/error.rb
29
+ - lib/poncho/errors.rb
30
+ - lib/poncho/filters.rb
31
+ - lib/poncho/json_method.rb
32
+ - lib/poncho/method.rb
33
+ - lib/poncho/param.rb
34
+ - lib/poncho/params.rb
35
+ - lib/poncho/params/array.rb
36
+ - lib/poncho/params/boolean.rb
37
+ - lib/poncho/params/boolean_string.rb
38
+ - lib/poncho/params/integer.rb
39
+ - lib/poncho/params/object.rb
40
+ - lib/poncho/params/resource.rb
41
+ - lib/poncho/params/string.rb
42
+ - lib/poncho/params/validations.rb
43
+ - lib/poncho/request.rb
44
+ - lib/poncho/resource.rb
45
+ - lib/poncho/response.rb
46
+ - lib/poncho/returns.rb
47
+ - lib/poncho/validations.rb
48
+ - lib/poncho/validations/exclusions.rb
49
+ - lib/poncho/validations/format.rb
50
+ - lib/poncho/validations/inclusions.rb
51
+ - lib/poncho/validations/length.rb
52
+ - lib/poncho/validations/presence.rb
53
+ - lib/poncho/validator.rb
54
+ - lib/poncho/version.rb
55
+ - poncho.gemspec
56
+ - test/poncho/test_method.rb
57
+ - test/poncho/test_resource.rb
58
+ homepage: https://github.com/stripe/poncho
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.24
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Poncho is an API to build APIs
82
+ test_files:
83
+ - test/poncho/test_method.rb
84
+ - test/poncho/test_resource.rb