acts_as_sdata 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/.gitignore +2 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.textile +200 -0
  4. data/Rakefile +20 -0
  5. data/VERSION +1 -0
  6. data/config/sdata.yml +13 -0
  7. data/config/sdata.yml.example +20 -0
  8. data/config/sdata.yml.tmpl.staging +14 -0
  9. data/generators/acts_as_sdata/acts_as_sdata_generator.rb +9 -0
  10. data/generators/acts_as_sdata/templates/migration.rb +69 -0
  11. data/init.rb +36 -0
  12. data/lib/s_data/active_record_extensions/base.rb +7 -0
  13. data/lib/s_data/active_record_extensions/mixin.rb +157 -0
  14. data/lib/s_data/active_record_extensions/sdata_uuid_mixin.rb +133 -0
  15. data/lib/s_data/atom_extensions/content_mixin.rb +14 -0
  16. data/lib/s_data/atom_extensions/entry_mixin.rb +41 -0
  17. data/lib/s_data/atom_extensions/nodes/digest.rb +48 -0
  18. data/lib/s_data/atom_extensions/nodes/payload.rb +34 -0
  19. data/lib/s_data/atom_extensions/nodes/sync_state.rb +14 -0
  20. data/lib/s_data/conditions_builder.rb +59 -0
  21. data/lib/s_data/controller_mixin.rb +11 -0
  22. data/lib/s_data/controller_mixin/actions.rb +87 -0
  23. data/lib/s_data/controller_mixin/collection_scope.rb +57 -0
  24. data/lib/s_data/controller_mixin/s_data_feed.rb +87 -0
  25. data/lib/s_data/controller_mixin/s_data_instance.rb +35 -0
  26. data/lib/s_data/diagnosis/application_controller_mixin.rb +16 -0
  27. data/lib/s_data/diagnosis/diagnosis.rb +130 -0
  28. data/lib/s_data/diagnosis/diagnosis_mapper.rb +39 -0
  29. data/lib/s_data/exceptions.rb +10 -0
  30. data/lib/s_data/formatting.rb +13 -0
  31. data/lib/s_data/namespace_definitions.rb +19 -0
  32. data/lib/s_data/payload.rb +158 -0
  33. data/lib/s_data/payload_map.rb +0 -0
  34. data/lib/s_data/payload_map/payload_map.rb +136 -0
  35. data/lib/s_data/payload_map/payload_map_hash.rb +39 -0
  36. data/lib/s_data/predicate.rb +31 -0
  37. data/lib/s_data/route_mapper.rb +143 -0
  38. data/lib/s_data/router_mixin.rb +10 -0
  39. data/lib/s_data/sync/controller_mixin.rb +122 -0
  40. data/lib/s_data/sync/sdata_syncing_mixin.rb +17 -0
  41. data/lib/s_data/virtual_base.rb +114 -0
  42. data/test/functional/Rakefile +0 -0
  43. data/test/unit/active_record_mixin/active_record_mixin_spec.rb +20 -0
  44. data/test/unit/active_record_mixin/acts_as_sdata_spec.rb +41 -0
  45. data/test/unit/active_record_mixin/find_by_sdata_instance_id_spec.rb +34 -0
  46. data/test/unit/active_record_mixin/payload_spec.rb +622 -0
  47. data/test/unit/active_record_mixin/to_atom_spec.rb +85 -0
  48. data/test/unit/atom_entry_mixin/atom_entry_mixin_spec.rb +11 -0
  49. data/test/unit/atom_entry_mixin/to_attributes_spec.rb +30 -0
  50. data/test/unit/class_stubs/address.rb +19 -0
  51. data/test/unit/class_stubs/contact.rb +25 -0
  52. data/test/unit/class_stubs/customer.rb +70 -0
  53. data/test/unit/class_stubs/model_base.rb +17 -0
  54. data/test/unit/class_stubs/payload.rb +15 -0
  55. data/test/unit/class_stubs/sd_uuid.rb +28 -0
  56. data/test/unit/class_stubs/user.rb +40 -0
  57. data/test/unit/conditions_builder_spec.rb +54 -0
  58. data/test/unit/controller_mixin/acts_as_sdata_spec.rb +29 -0
  59. data/test/unit/controller_mixin/build_sdata_feed_spec.rb +50 -0
  60. data/test/unit/controller_mixin/controller_mixin_spec.rb +22 -0
  61. data/test/unit/controller_mixin/diagnosis_spec.rb +232 -0
  62. data/test/unit/controller_mixin/sdata_collection_spec.rb +78 -0
  63. data/test/unit/controller_mixin/sdata_create_instance_spec.rb +173 -0
  64. data/test/unit/controller_mixin/sdata_opensearch_and_links_spec.rb +382 -0
  65. data/test/unit/controller_mixin/sdata_scope/linked_model_spec.rb +58 -0
  66. data/test/unit/controller_mixin/sdata_scope/non_linked_model_spec.rb +66 -0
  67. data/test/unit/controller_mixin/sdata_scope/scoping_in_config_spec.rb +64 -0
  68. data/test/unit/controller_mixin/sdata_show_instance_spec.rb +98 -0
  69. data/test/unit/controller_mixin/sdata_update_instance_spec.rb +65 -0
  70. data/test/unit/payload_map/payload_map_hash_spec.rb +84 -0
  71. data/test/unit/payload_map/payload_map_spec.rb +144 -0
  72. data/test/unit/predicate_spec.rb +59 -0
  73. data/test/unit/router_mixin/routes_spec.rb +138 -0
  74. data/test/unit/spec.opts +4 -0
  75. data/test/unit/spec_helper.rb +47 -0
  76. data/test/unit/spec_helpers/nokogiri_extensions.rb +16 -0
  77. data/test/unit/sync_controller_mixin/controller_mixin_spec.rb +22 -0
  78. data/test/unit/sync_controller_mixin/sdata_collection_sync_feed_spec.rb +69 -0
  79. metadata +175 -0
@@ -0,0 +1,85 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe SData::ActiveRecordExtensions::Mixin, "#to_atom" do
4
+ describe "given a class extended by ActiveRecordExtensions" do
5
+ before :all do
6
+ class Base
7
+ extend SData::ActiveRecordExtensions::Mixin
8
+ end
9
+ end
10
+
11
+ describe "when .acts_as_sdata is called without arguments" do
12
+ before :each do
13
+ Base.class_eval { acts_as_sdata }
14
+ @model = Base.new
15
+ @model.stub! :id => 1, :name => 'John Smith', :updated_at => Time.now - 1.day, :created_by => @model, :sage_username => 'basic_user'
16
+ @model.stub! :sdata_content => "Base ##{@model.id}: #{@model.name}", :attributes => {}
17
+ end
18
+
19
+ it "should return an Atom::Entry instance" do
20
+ @model.to_atom(:dataset => '-').should be_kind_of(Atom::Entry)
21
+ end
22
+
23
+ it "should assign model name to Atom::Entry#content" do
24
+ @model.to_atom(:dataset => '-').content.should == 'Base #1: John Smith'
25
+ end
26
+
27
+ it "should assign model name and id to Atom::Entry#title" do
28
+ @model.to_atom(:dataset => '-').title.should == 'Base 1'
29
+ end
30
+
31
+ it "should assign Atom::Entry#updated" do
32
+ Time.parse(@model.to_atom(:dataset => '-').updated).should < Time.now-1.day
33
+ Time.parse(@model.to_atom(:dataset => '-').updated).should > Time.now-1.day-1.minute
34
+ end
35
+
36
+ it "should assign Atom::Entry#links" do
37
+ @model.to_atom(:dataset => '-').links.size.should == 1
38
+ @model.to_atom(:dataset => '-').links[0].rel.should == 'self'
39
+ @model.to_atom(:dataset => '-').links[0].href.should == "http://www.example.com/sdata/example/myContract/-/bases('1')"
40
+ end
41
+
42
+ it "should assign Atom::Entry#links when param query is present" do
43
+ @model.to_atom(:dataset => '-', :select => 'attribute').links.size.should == 1
44
+ @model.to_atom(:dataset => '-', :select => 'attribute').links[0].rel.should == 'self'
45
+ @model.to_atom(:dataset => '-', :select => 'attribute').links[0].href.should == "http://www.example.com/sdata/example/myContract/-/bases('1')?select=attribute"
46
+ end
47
+
48
+ it "should assign Atom::Entry::id" do
49
+ @model.to_atom(:dataset => '-').id.should == "http://www.example.com/sdata/example/myContract/-/bases('1')"
50
+ end
51
+
52
+ it "should assign Atom::Entry::categories" do
53
+ @model.to_atom.categories.size.should == 1
54
+ @model.to_atom.categories[0].term.should == "base"
55
+ @model.to_atom.categories[0].label.should == "Base"
56
+ @model.to_atom.categories[0].scheme.should == "http://schemas.sage.com/sdata/categories"
57
+ end
58
+
59
+ # #QUESTION: Why is it commented out?
60
+ # it "should expose activerecord attributes in a simple XML extension" do
61
+ # @model.stub! :attributes => { :last_name => "Washington", :first_name => "George" }
62
+ # atom_entry = @model.to_atom
63
+ # atom_entry['http://sdata.sage.com/schemes/attributes'].should == { 'last_name' => ["Washington"], 'first_name' => ["George"] }
64
+ # end
65
+ end
66
+
67
+ describe "when .acts_as_sdata is called with arguments" do
68
+ before :each do
69
+ Base.class_eval do
70
+ acts_as_sdata :title => lambda { "#{id}: #{name}" },
71
+ :content => lambda { "#{name}" }
72
+ end
73
+
74
+ @model = Base.new
75
+ @model.stub! :id => 1, :name => 'Test', :updated_at => Time.now - 1.day, :created_by => @model, :sage_username => 'basic_user'
76
+ @model.stub! :sdata_content => "Base ##{@model.id}: #{@model.name}", :to_xml => ''
77
+ end
78
+
79
+ it "should evaulate given lambda's in the correct context" do
80
+ @model.to_atom.title.should == '1: Test'
81
+ @model.to_atom.content.should == 'Base #1: Test'
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,11 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ include SData
4
+
5
+ describe "Atom extensions" do
6
+ describe "given an extended Atom::Entry" do
7
+ it "should respond to #to_attributes" do
8
+ Atom::Entry.new.should respond_to(:to_attributes)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ include SData
4
+
5
+ describe Atom::Entry, "#to_attributes" do
6
+ describe "given an Atom::Entry extended with AtomExtensions::Entry" do
7
+ describe "when model has attributes in a simple XML extension" do
8
+ before :each do
9
+ @entry = Atom::Entry.new
10
+ @entry['http://sdata.sage.com/schemes/attributes', 'first_name'] << 'George'
11
+ @entry['http://sdata.sage.com/schemes/attributes', 'last_name'] << 'Washington'
12
+ end
13
+
14
+ it "should return an ActiveRecord-friendly hash" do
15
+ @entry.to_attributes.should == { 'first_name' => 'George', 'last_name' => 'Washington' }
16
+ end
17
+
18
+ describe "when some attribute has multiple values" do
19
+ before :each do
20
+ @entry['http://sdata.sage.com/schemes/attributes', 'initials'] << 'G.'
21
+ @entry['http://sdata.sage.com/schemes/attributes', 'initials'] << 'GW'
22
+ end
23
+
24
+ it "should take the first one" do
25
+ @entry.to_attributes['initials'].should == 'G.'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ # SData::VirtualBase is uninitialized for some reason without below line
2
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
3
+
4
+ class Address < SData::VirtualBase
5
+
6
+ attr_writer :city, :created_at, :updated_at, :owner
7
+ def populate_defaults
8
+ self.city = @city || "Vancouver"
9
+ self.created_at = @created_at || Time.now-2.days
10
+ self.updated_at = @updated_at || Time.now-1.day
11
+ self
12
+ end
13
+
14
+ define_payload_map :customer_id => { :proc => lambda { @customer_id }, :precedence => 2 },
15
+ :city => { :proc => lambda { @city }, :precedence => 2 },
16
+ :created_at => { :proc => lambda { @created_at }, :precedence => 4 },
17
+ :updated_at => { :proc => lambda { @updated_at }, :precedence => 4 }
18
+
19
+ end
@@ -0,0 +1,25 @@
1
+ class Contact < ModelBase
2
+
3
+ attr_writer :customer, :name, :created_at, :updated_at
4
+
5
+ def baze
6
+ self
7
+ end
8
+
9
+ def populate_defaults
10
+ self.id = @id || object_id.abs
11
+ self.name = @name || "Contact Name"
12
+ self.created_at = @created_at || Time.now-2.days
13
+ self.updated_at = @updated_at || Time.now-1.day
14
+ self
15
+ end
16
+
17
+ def sdata_content
18
+ "Contact ##{self.id}: #{self.name}"
19
+ end
20
+
21
+ define_payload_map :name => { :proc => lambda { @name }, :precedence => 2 },
22
+ :customer_id => { :proc => lambda { @customer_id }, :precedence => 2 },
23
+ :created_at => { :proc => lambda { @created_at }, :precedence => 4 },
24
+ :updated_at => { :proc => lambda { @updated_at }, :precedence => 4 }
25
+ end
@@ -0,0 +1,70 @@
1
+ class Customer < ModelBase
2
+
3
+ attr_writer :created_by, :name, :number, :contacts, :created_at, :updated_at, :address
4
+
5
+ def self.is_a?(value)
6
+ # Don't really like doing this but don't see a quick better way
7
+ return true if value == SData::VirtualBase
8
+ super
9
+ end
10
+ def baze
11
+ self
12
+ end
13
+ def populate_defaults
14
+ self.id = @id || object_id.abs
15
+ self.name = @name || "Customer Name"
16
+ self.number = @number || 12345
17
+ self.contacts = @contacts || build_contacts(:number => 2, :created_by => self)
18
+ self.created_at = @created_at || Time.now-2.days
19
+ self.updated_at = @updated_at || Time.now-1.day
20
+ self.address = @address || Address.new(self)
21
+ self
22
+ end
23
+
24
+ def contacts
25
+ @contacts || []
26
+ end
27
+
28
+ def default_contact
29
+ self.contacts[0]
30
+ end
31
+
32
+ def created_by_id
33
+ @created_by ? @created_by.id : nil
34
+ end
35
+
36
+ def sdata_content
37
+ "Customer ##{self.id}: #{self.name}"
38
+ end
39
+
40
+ define_payload_map :name => { :proc => lambda { @name }, :precedence => 2 },
41
+ :number => { :proc => lambda { @number }, :precedence => 5 },
42
+ :created_at => { :proc => lambda { @created_at }, :precedence => 3 },
43
+ :updated_at => { :proc => lambda { @updated_at }, :precedence => 3 },
44
+ :my_default_contact => { :proc => lambda { self.default_contact }, :precedence => 3 },
45
+ :my_contacts => { :proc => lambda { @contacts },
46
+ :precedence => 5, #treated as a CHILD of customer
47
+ :type => :child
48
+ },
49
+ :associated_contacts => { :proc => lambda { @contacts },
50
+ :precedence => 3,
51
+ :type => :association
52
+ }, #treated as an ASSOCIATION of customer
53
+
54
+ :address => { :proc => lambda { @address }, :precedence => 5 },
55
+
56
+ :simple_elements => { :static_value => ['element 1', 'element 2'], :precedence => 6 },
57
+
58
+ :hash_value => { :static_value => { :simple_object_key => 'simple_object_value' }, :precedence => 6 }
59
+
60
+ def build_contacts(options)
61
+ the_contacts = []
62
+ for i in 1..options[:number] do
63
+ c = Contact.new
64
+ c.id = i
65
+ c.customer = options[:created_by]
66
+ the_contacts << c
67
+ end
68
+ the_contacts
69
+ end
70
+ end
@@ -0,0 +1,17 @@
1
+ class ModelBase
2
+ extend SData::PayloadMap
3
+ attr_accessor :id
4
+
5
+ def self.name
6
+ super_name = super
7
+ "SData::Contracts::CrmErp::#{super_name}"
8
+ end
9
+
10
+ def attributes
11
+ {}
12
+ end
13
+
14
+ def sdata_options
15
+ {}
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ TradingAccount = Struct.new :id, :uuid
2
+
3
+ class Payload < Struct.new(:trading_account)
4
+ def to_xml
5
+ builder = Nokogiri::XML::Builder.new do |xml|
6
+ xml.payload(
7
+ 'xmlns:sdata' => "http://schemas.sage.com/sdata/2008/1") {
8
+ xml['sdata'].tradingAccount :uuid => trading_account.uuid,
9
+ :url => "http://www.billingboss.com/myApp/myContract/-/tradingAccounts!#{trading_account.id}"
10
+ }
11
+ end
12
+
13
+ builder.to_xml
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module SData
2
+ class SdUuid
3
+ @@test_uuids = []
4
+ [
5
+ {:sd_class => 'Customer', :bb_model_type => 'Customer', :bb_model_id => 12345, :uuid => 'CUST-10000'},
6
+ {:sd_class => 'Address', :bb_model_type => 'Customer', :bb_model_id => 12345, :uuid => 'ADDR-10001'},
7
+ {:sd_class => 'Contact', :bb_model_type => 'Contact', :bb_model_id => 23456, :uuid => 'CONT-10002'},
8
+ {:sd_class => 'Contact', :bb_model_type => 'Contact', :bb_model_id => 123, :uuid => 'C-123-456'},
9
+ {:sd_class => 'Customer', :bb_model_type => 'Customer', :bb_model_id => 23456, :uuid => 'CUST-10003'},
10
+ ].each do |params|
11
+ @@test_uuids << OpenStruct.new(params)
12
+ end
13
+
14
+
15
+ def self.first(params)
16
+ match = nil
17
+ @@test_uuids.each do |record|
18
+ if (record.sd_class == params[:conditions][:sd_class] and
19
+ record.bb_model_type == params[:conditions][:bb_model_type] and
20
+ record.bb_model_id == params[:conditions][:bb_model_id])
21
+
22
+ match = record
23
+ end
24
+ end
25
+ return match
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ class User < ModelBase
2
+
3
+ attr_writer :name, :password, :customers, :created_at, :updated_at
4
+ def populate_defaults
5
+ self.id = @id || object_id.abs
6
+ self.name = @name || "username"
7
+ self.password = @password || "user_password"
8
+ self.customers = @customers || build_customers(:number => 3, :created_by => self)
9
+ self.created_at = @created_at || Time.now-2.days
10
+ self.updated_at = @updated_at || Time.now-1.day
11
+ self
12
+ end
13
+
14
+ def record_id
15
+ @record ? @record.id : nil
16
+ end
17
+
18
+ def sdata_content
19
+ "User ##{self.id}: #{self.name}"
20
+ end
21
+
22
+ define_payload_map :name => { :proc => lambda { @name }, :precedence => 2 },
23
+ :record_id => { :proc => lambda { @record_id }, :precedence => 2 },
24
+ :uuid => { :proc => lambda { @uuid }, :precedence => 2 },
25
+ :created_at => { :proc => lambda { @created_at }, :precedence => 3 },
26
+ :updated_at => { :proc => lambda { @updated_at }, :precedence => 3 }
27
+
28
+ protected
29
+
30
+ def build_customers(options)
31
+ the_customers = []
32
+ for i in 1..options[:number] do
33
+ c = Customer.new
34
+ c.id = i
35
+ c.created_by = options[:created_by]
36
+ the_customers << c
37
+ end
38
+ the_customers
39
+ end
40
+ end
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ include SData
4
+
5
+ describe ConditionsBuilder do
6
+ describe "#build_conditions" do
7
+ it "should correctly build equality" do
8
+ conditions = ConditionsBuilder.build_conditions 'born_at', :eq, '1900'
9
+ conditions.should == ["#{quoted('born_at')} = ?", '1900']
10
+ end
11
+
12
+ it "should correctly build '>'" do
13
+ conditions = ConditionsBuilder.build_conditions 'born_at', :gt, '1900'
14
+ conditions.should == ["#{quoted('born_at')} > ?", '1900']
15
+ end
16
+
17
+ it "should correctly build '<'" do
18
+ conditions = ConditionsBuilder.build_conditions 'born_at', :lt, '1900'
19
+ conditions.should == ["#{quoted('born_at')} < ?", '1900']
20
+ end
21
+
22
+ it "should currectly build '<=' " do
23
+ conditions = ConditionsBuilder.build_conditions 'born_at', :lteq, '1900'
24
+ conditions.should == ["#{quoted('born_at')} <= ?", '1900']
25
+ end
26
+
27
+ it "should currectly build '>='" do
28
+ conditions = ConditionsBuilder.build_conditions 'born_at', :gteq, '1900'
29
+ conditions.should == ["#{quoted('born_at')} >= ?", '1900']
30
+ end
31
+
32
+ it "should currectly build '<>'" do
33
+ conditions = ConditionsBuilder.build_conditions 'born_at', :ne, '1900'
34
+ conditions.should == ["#{quoted('born_at')} <> ?", '1900']
35
+ end
36
+
37
+ it "should currectly build 'between'" do
38
+ conditions = ConditionsBuilder.build_conditions 'born_at', :between, '1900', '1905'
39
+ conditions.should == ["#{quoted('born_at')} BETWEEN ? AND ?", '1900', '1905']
40
+ end
41
+
42
+ it "should return empty hash is arguments are invalid" do
43
+ ConditionsBuilder.build_conditions(nil, :gt, 1).should == []
44
+ ConditionsBuilder.build_conditions('field', :invalid_relation, 1).should == []
45
+ ConditionsBuilder.build_conditions('field', :gt).should == []
46
+ ConditionsBuilder.build_conditions('field', :gt, 'value', 'redundant_value').should == []
47
+ ConditionsBuilder.build_conditions('field', :between, 'insufficient value').should == []
48
+ end
49
+
50
+ def quoted(column_name)
51
+ ActiveRecord::Base.connection.quote_column_name(column_name)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ include SData
4
+
5
+ describe ControllerMixin, ".acts_as_sdata" do
6
+ describe "given an ActionController::Base class extended by ControllerMixin" do
7
+ before :all do
8
+ Base = Class.new ActionController::Base
9
+ Base.extend ControllerMixin
10
+ end
11
+
12
+ before :each do
13
+ @options = { :model => Class.new }
14
+ Base.acts_as_sdata @options
15
+ end
16
+
17
+ it "should make passed options available for class" do
18
+ Base.sdata_options.should == @options
19
+ end
20
+
21
+ it "should make passed options available for instances" do
22
+ Base.new.sdata_options.should == @options
23
+ end
24
+
25
+ it "should include instance methods" do
26
+ Base.new.should respond_to(:build_sdata_feed)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ include SData
4
+
5
+ describe ControllerMixin, "#build_sdata_feed" do
6
+ describe "given a controller which acts as sdata" do
7
+ before :all do
8
+ Base = Class.new(ActionController::Base)
9
+ Base.extend ControllerMixin
10
+ Base.__send__ :define_method, :build_sdata_feed, lambda { super }
11
+
12
+ Base.acts_as_sdata :feed => { :id => 'some-unique-id',
13
+ :author => 'Test Author',
14
+ :path => '/test_resource',
15
+ :title => 'List of Test Items' }
16
+ end
17
+
18
+ before :each do
19
+ @controller = Base.new
20
+ @controller.stub! :request => OpenStruct.new(
21
+ :protocol => 'http',
22
+ :host_with_port => 'http://example.com',
23
+ :request_uri => Base.sdata_options[:feed][:path],
24
+ :path => SData.store_path + '/-/testResource'),
25
+ :params => {:dataset => '-'},
26
+ :sdata_options => {:feed => {}, :model => OpenStruct.new(:name => 'base', :sdata_resource_kind_url => '')}
27
+
28
+
29
+ end
30
+
31
+ it "should return Atom::Feed instance" do
32
+ @controller.build_sdata_feed.should be_kind_of(Atom::Feed)
33
+ end
34
+
35
+ it "should not contain any entries" do
36
+ @controller.build_sdata_feed.entries.should be_empty
37
+ end
38
+
39
+ it "should adopt passed sdata_options" do
40
+ @controller.build_sdata_feed.id = Base.sdata_options[:feed][:id]
41
+ end
42
+
43
+ it "should assign categories" do
44
+ @controller.build_sdata_feed.categories.size.should == 1
45
+ @controller.build_sdata_feed.categories[0].term.should == 'bases'
46
+ @controller.build_sdata_feed.categories[0].label.should == 'Bases'
47
+ @controller.build_sdata_feed.categories[0].scheme.should == "http://schemas.sage.com/sdata/categories"
48
+ end
49
+ end
50
+ end