arusarka-dynamic-active-resource 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/spec/dynamic_active_resource/associations_spec.rb +27 -0
- data/spec/dynamic_active_resource/base_spec.rb +10 -0
- data/spec/dynamic_active_resource/common_dynamic_class_instance_methods_spec.rb +21 -0
- data/spec/dynamic_active_resource/version_spec.rb +7 -0
- data/test/integration/test_dynamic_active_resource.rb +24 -0
- data/test/integration/test_dynamic_active_resource2.rb +44 -0
- metadata +7 -1
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class DummyAssociationClass
|
4
|
+
extend DynamicActiveResource::Associations
|
5
|
+
end
|
6
|
+
|
7
|
+
describe 'DynamicActiveResource::AssociationClass' do
|
8
|
+
after(:each) do
|
9
|
+
DummyAssociationClass.instance_variable_set(:@associations, nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set a has_many association properly" do
|
13
|
+
class DummyAssociationClass
|
14
|
+
has_many :dummies
|
15
|
+
end
|
16
|
+
associations = DummyAssociationClass.instance_variable_get(:@associations)
|
17
|
+
associations.first.should be_instance_of(DynamicActiveResource::Associations::HasMany)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set a belongs_to association properly" do
|
21
|
+
class DummyAssociationClass
|
22
|
+
belongs_to :test
|
23
|
+
end
|
24
|
+
associations = DummyAssociationClass.instance_variable_get(:@associations)
|
25
|
+
associations.first.should be_instance_of(DynamicActiveResource::Associations::BelongsTo)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe 'DynamicActiveResource::Base' do
|
4
|
+
it "should extend the subclass properly" do
|
5
|
+
DynamicActiveResource::CommonClassMethods.should_receive(:extended)
|
6
|
+
DynamicActiveResource::Associations.should_receive(:extended)
|
7
|
+
class Child < DynamicActiveResource::Base
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
class Resource
|
4
|
+
include DynamicActiveResource::CommonDynamicClassInstanceMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
describe 'DynamicActiveResource::CommonDynamicClassInstanceMethods' do
|
8
|
+
it "should find the resource identifier properly" do
|
9
|
+
resource = Resource.new
|
10
|
+
resource.should_receive(:id).and_return(1)
|
11
|
+
resource.resource_identifier.should == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be able to detect a association method properly" do
|
15
|
+
resource = Resource.new
|
16
|
+
association = DynamicActiveResource::Associations::Base.new :person
|
17
|
+
Resource.instance_variable_set(:@associations, [association])
|
18
|
+
resource.send(:association_method?, 'person').should == true
|
19
|
+
Resource.instance_variable_set(:@associations, nil)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "../../lib/dynamic_active_resource"
|
2
|
+
|
3
|
+
class Card < DynARBase
|
4
|
+
module ClassMethods
|
5
|
+
def find_without_pagination(*args)
|
6
|
+
scope = args.slice!(0)
|
7
|
+
options = args.slice!(0) || {}
|
8
|
+
options[:params] ||= {}
|
9
|
+
options[:params].merge!({:page => 'all'})
|
10
|
+
|
11
|
+
# call ActiveResource::Base::find with proper options
|
12
|
+
find(scope, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Card.site = 'http://localhost:9090/projects/api_test'
|
18
|
+
Card.user = 'testuser'
|
19
|
+
Card.password = 'testuser'
|
20
|
+
|
21
|
+
puts Card.find_without_pagination(:all).size
|
22
|
+
|
23
|
+
Card.site = 'http://localhost:9090/projects/agile_hybrib_project'
|
24
|
+
puts Card.find_without_pagination(:all).size
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../lib/dynamic_active_resource'
|
2
|
+
|
3
|
+
class Card < DynARBase
|
4
|
+
belongs_to :project
|
5
|
+
module DynamicClassSingletonMethods
|
6
|
+
def find_without_pagination(*args)
|
7
|
+
scope = args.slice!(0)
|
8
|
+
options = args.slice!(0) || {}
|
9
|
+
options[:params] ||= {}
|
10
|
+
options[:params].merge!({:page => 'all'})
|
11
|
+
# call ActiveResource::Base::find with proper options
|
12
|
+
find(scope, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Project < DynARBase
|
18
|
+
has_many :cards
|
19
|
+
module DynamicClassInstanceMethods
|
20
|
+
def resource_identifier
|
21
|
+
identifier()
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Project.site = 'http://localhost:9090/'
|
27
|
+
Project.user = 'testuser'
|
28
|
+
Project.password = 'testuser'
|
29
|
+
proj = Project.find('api_test')
|
30
|
+
|
31
|
+
puts proj.resource_identifier
|
32
|
+
|
33
|
+
# association = proj.class.instance_variable_get(:@children_associations).detect { |association| association[:method] }
|
34
|
+
# card_class = eval(association[:class])
|
35
|
+
# puts proj.send(:child_association_method?, 'cards')
|
36
|
+
|
37
|
+
cards = proj.cards
|
38
|
+
# puts cards.send(:create_resource_class).collection_path
|
39
|
+
puts cards.size
|
40
|
+
# puts cards[0].class.instance_variable_get(:@associations)
|
41
|
+
proj1 = cards[0].project
|
42
|
+
puts proj1.identifier
|
43
|
+
#
|
44
|
+
puts proj1.cards.size
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arusarka-dynamic-active-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- asur
|
@@ -41,6 +41,12 @@ files:
|
|
41
41
|
- lib/dynamic_active_resource/helpers.rb
|
42
42
|
- lib/dynamic_active_resource/version.rb
|
43
43
|
- lib/dynamic_active_resource.rb
|
44
|
+
- test/integration/test_dynamic_active_resource.rb
|
45
|
+
- test/integration/test_dynamic_active_resource2.rb
|
46
|
+
- spec/dynamic_active_resource/associations_spec.rb
|
47
|
+
- spec/dynamic_active_resource/base_spec.rb
|
48
|
+
- spec/dynamic_active_resource/common_dynamic_class_instance_methods_spec.rb
|
49
|
+
- spec/dynamic_active_resource/version_spec.rb
|
44
50
|
- README
|
45
51
|
- History.txt
|
46
52
|
- init.rb
|