ar_http_wrapper 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,4 +3,7 @@
3
3
  = Tests
4
4
 
5
5
  require ar_http_wrapper/spec_support
6
- it_behaves_like "ActiveRecordApiWrapper"
6
+ put in inside api class tests:
7
+ it_behaves_like "ActiveRecordApiWrapper", klass, mountpoint, apiversion
8
+
9
+ + add to spec_helper...
@@ -2,9 +2,13 @@ module ActiveRecordApiWrapper
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  module ClassMethods
5
+ def klass_to_param_key
6
+ self.to_s.underscore.split('/').last.to_sym
7
+ end
5
8
  def api(api_class)
6
9
  klass = self
7
10
  klass_name = self.to_s.underscore
11
+ klass_to_param_key = klass.klass_to_param_key
8
12
 
9
13
  api_class.resource :"#{klass_name}" do
10
14
  api_class.desc "Builds a record."
@@ -14,19 +18,19 @@ module ActiveRecordApiWrapper
14
18
 
15
19
  api_class.desc "Creates a record."
16
20
  api_class.params do
17
- requires klass.to_s.underscore.to_sym, :type => Hash, :desc => "The new record attributes."
21
+ requires klass_to_param_key, :type => Hash, :desc => "The new record attributes."
18
22
  end
19
23
  api_class.post "/" do
20
- klass.create(params[klass.to_s.underscore.to_sym])
24
+ klass.create(params[klass_to_param_key])
21
25
  end
22
26
 
23
27
  api_class.desc "Updates a record."
24
28
  api_class.params do
25
29
  requires :id, :desc => "The record id."
26
- requires klass.to_s.underscore.to_sym, :type => Hash, :desc => "The updated record attributes."
30
+ requires klass_to_param_key, :type => Hash, :desc => "The updated record attributes."
27
31
  end
28
32
  api_class.put "/:id" do
29
- updated_attr = params[klass.to_s.underscore.to_sym]
33
+ updated_attr = params[klass_to_param_key]
30
34
  instance = klass.find_by_id(params[:id])
31
35
  instance.try(:update_attributes,updated_attr)
32
36
  end
@@ -1,7 +1,7 @@
1
1
  shared_examples "ActiveRecordApiWrapper" do |klass,mountpoint,api_version|
2
2
  subject {klass}
3
3
  let(:mountpoint) {mountpoint}
4
- let(:api_version) {nil}
4
+ let(:api_version) {api_version}
5
5
  def subject_name
6
6
  subject.to_s.underscore
7
7
  end
@@ -9,7 +9,7 @@ shared_examples "ActiveRecordApiWrapper" do |klass,mountpoint,api_version|
9
9
  api_version ? api_version+'/' : ''
10
10
  end
11
11
  def to_path(_path='')
12
- "#{mountpoint}/#{api_version}#{subject_name}/#{_path}"
12
+ "#{mountpoint}/#{api_version_path}#{subject_name}/#{_path}"
13
13
  end
14
14
 
15
15
  describe "GET new" do
@@ -36,11 +36,11 @@ shared_examples "ActiveRecordApiWrapper" do |klass,mountpoint,api_version|
36
36
  subject.should_receive(:create).with(@test_instance).and_return(@test_instance)
37
37
  end
38
38
  it "creates instance" do
39
- post "#{to_path}", subject.to_s.underscore.to_sym => @test_instance
39
+ post "#{to_path}", subject.klass_to_param_key => @test_instance
40
40
  response.status.should == 201
41
41
  end
42
42
  it "returns instance" do
43
- post "#{to_path}", subject.to_s.underscore.to_sym => @test_instance
43
+ post "#{to_path}", subject.klass_to_param_key => @test_instance
44
44
  response.status.should == 201
45
45
  JSON.parse(response.body).should == @test_instance
46
46
  end
@@ -55,11 +55,11 @@ shared_examples "ActiveRecordApiWrapper" do |klass,mountpoint,api_version|
55
55
  @test_instance.should_receive(:update_attributes).with(@updated_instance).and_return(@updated_instance)
56
56
  end
57
57
  it "finds instance" do
58
- put "#{to_path(@id)}", subject.to_s.underscore.to_sym => @updated_instance
58
+ put "#{to_path(@id)}", subject.klass_to_param_key => @updated_instance
59
59
  response.status.should == 200
60
60
  end
61
61
  it "returns instance" do
62
- put "#{to_path(@id)}", subject.to_s.underscore.to_sym => @updated_instance
62
+ put "#{to_path(@id)}", subject.klass_to_param_key => @updated_instance
63
63
  response.status.should == 200
64
64
  JSON.parse(response.body).should == @updated_instance
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module ArHttpWrapper
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_http_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-13 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails