backframe 0.0.49 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +16 -0
  3. data/.gitignore +2 -2
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +1156 -0
  6. data/Gemfile +9 -13
  7. data/README.md +133 -4
  8. data/Rakefile +3 -7
  9. data/backframe.gemspec +10 -11
  10. data/circle.yml +5 -2
  11. data/lib/backframe.rb +21 -34
  12. data/lib/backframe/mime.rb +4 -0
  13. data/lib/backframe/query.rb +48 -0
  14. data/lib/backframe/query/sort.rb +29 -0
  15. data/lib/backframe/railtie.rb +1 -16
  16. data/lib/backframe/response.rb +60 -0
  17. data/lib/backframe/response/adapter/csv.rb +39 -0
  18. data/lib/backframe/response/adapter/json.rb +53 -0
  19. data/lib/backframe/response/adapter/xlsx.rb +41 -0
  20. data/lib/backframe/response/adapter/xml.rb +37 -0
  21. data/lib/backframe/response/collection.rb +43 -0
  22. data/lib/backframe/response/fields.rb +62 -0
  23. data/lib/backframe/response/record.rb +38 -0
  24. data/lib/backframe/service.rb +60 -0
  25. data/lib/backframe/service/result/base.rb +24 -0
  26. data/lib/backframe/service/result/failure.rb +21 -0
  27. data/lib/backframe/service/result/success.rb +21 -0
  28. data/lib/backframe/version.rb +1 -1
  29. data/spec/fixtures/active_record.rb +22 -0
  30. data/spec/fixtures/models.rb +25 -0
  31. data/spec/fixtures/queries.rb +28 -0
  32. data/spec/fixtures/seeds.rb +12 -0
  33. data/spec/fixtures/serializers.rb +23 -0
  34. data/spec/fixtures/services.rb +26 -0
  35. data/spec/query/sort_spec.rb +47 -0
  36. data/spec/query_spec.rb +63 -0
  37. data/spec/response/adapter/csv_spec.rb +47 -0
  38. data/spec/response/adapter/json_spec.rb +66 -0
  39. data/spec/response/adapter/xlsx_spec.rb +59 -0
  40. data/spec/response/adapter/xml_spec.rb +63 -0
  41. data/spec/response/fields_spec.rb +45 -0
  42. data/spec/response/record_spec.rb +45 -0
  43. data/spec/response_spec.rb +153 -0
  44. data/spec/service/result/failure_spec.rb +16 -0
  45. data/spec/service/result/sucess_spec.rb +17 -0
  46. data/spec/service_spec.rb +16 -0
  47. data/spec/spec_helper.rb +15 -52
  48. metadata +78 -81
  49. data/lib/backframe/actioncontroller/acts_as_activation.rb +0 -70
  50. data/lib/backframe/actioncontroller/acts_as_api.rb +0 -39
  51. data/lib/backframe/actioncontroller/acts_as_api/adapter.rb +0 -53
  52. data/lib/backframe/actioncontroller/acts_as_api/errors.rb +0 -48
  53. data/lib/backframe/actioncontroller/acts_as_api/headers.rb +0 -11
  54. data/lib/backframe/actioncontroller/acts_as_api/page.rb +0 -181
  55. data/lib/backframe/actioncontroller/acts_as_reset.rb +0 -86
  56. data/lib/backframe/actioncontroller/acts_as_resource.rb +0 -92
  57. data/lib/backframe/actioncontroller/acts_as_resource/actions.rb +0 -100
  58. data/lib/backframe/actioncontroller/acts_as_session.rb +0 -80
  59. data/lib/backframe/activerecord/acts_as_activable.rb +0 -50
  60. data/lib/backframe/activerecord/acts_as_distinct.rb +0 -49
  61. data/lib/backframe/activerecord/acts_as_enum.rb +0 -62
  62. data/lib/backframe/activerecord/acts_as_orderable.rb +0 -40
  63. data/lib/backframe/activerecord/acts_as_percent.rb +0 -46
  64. data/lib/backframe/activerecord/acts_as_phone.rb +0 -59
  65. data/lib/backframe/activerecord/acts_as_user.rb +0 -101
  66. data/lib/backframe/activerecord/default_values.rb +0 -32
  67. data/lib/backframe/activerecord/filter_sort.rb +0 -79
  68. data/lib/backframe/activerecord/migration.rb +0 -25
  69. data/lib/backframe/image_cache/image_cache.rb +0 -45
  70. data/lib/backframe/image_cache/lib/asset.rb +0 -109
  71. data/lib/backframe/image_cache/lib/cache.rb +0 -67
  72. data/lib/backframe/image_cache/lib/conversions.rb +0 -132
  73. data/lib/backframe/models/activation.rb +0 -60
  74. data/lib/backframe/models/activity.rb +0 -40
  75. data/lib/backframe/models/reset.rb +0 -59
  76. data/lib/backframe/models/story.rb +0 -9
  77. data/lib/backframe/serializers/activity_serializer.rb +0 -44
  78. data/spec/backframe/acts_as_api_spec.rb +0 -225
  79. data/spec/backframe/acts_as_resource_spec.rb +0 -178
  80. data/spec/support/example_factory.rb +0 -9
  81. data/spec/support/example_serializer.rb +0 -3
  82. data/spec/support/schema.rb +0 -8
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Backframe
4
- VERSION = '0.0.49'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -0,0 +1,22 @@
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
4
+
5
+ ActiveRecord::Schema.define do
6
+
7
+ self.verbose = false
8
+
9
+ create_table :contacts, force: true do |t|
10
+ t.string :first_name
11
+ t.string :last_name
12
+ t.string :email
13
+ t.references :photo
14
+ t.timestamps null: false
15
+ end
16
+
17
+ create_table :photos, force: true do |t|
18
+ t.string :path
19
+ t.timestamps null: false
20
+ end
21
+
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_record'
2
+
3
+ module Backframe
4
+
5
+ module Fixtures
6
+
7
+ class Contact < ActiveRecord::Base
8
+
9
+ belongs_to :photo
10
+
11
+ validates :first_name, presence: true
12
+ validates :last_name, presence: true
13
+ validates :email, presence: true
14
+
15
+ end
16
+
17
+ class Photo < ActiveRecord::Base
18
+
19
+ has_one :contact
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,28 @@
1
+ require 'backframe'
2
+
3
+ module Backframe
4
+
5
+ module Fixtures
6
+
7
+ class ContactQuery < Backframe::Query
8
+
9
+ def filter(records, filters)
10
+ records = records.where(first_name: filters[:first_name]) if filters.key?(:first_name)
11
+ records = records.where(last_name: filters[:last_name]) if filters.key?(:last_name)
12
+ records = records.where(email: filters[:email]) if filters.key?(:email)
13
+ records
14
+ end
15
+
16
+ end
17
+
18
+ class PhotoQuery < Backframe::Query
19
+
20
+ def filter(records, filters)
21
+ records
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,12 @@
1
+ require 'active_record'
2
+
3
+
4
+ greg_photo = Backframe::Fixtures::Photo.create(path: '/images/greg.jpg')
5
+ megan_photo = Backframe::Fixtures::Photo.create(path: '/images/megan.jpg')
6
+ kath_photo = Backframe::Fixtures::Photo.create(path: '/images/kath.jpg')
7
+ armand_photo = Backframe::Fixtures::Photo.create(path: '/images/armand.jpg')
8
+
9
+ greg = Backframe::Fixtures::Contact.create(first_name: 'Greg', last_name: 'Kops', email: 'greg@thinktopography.com', photo: greg_photo)
10
+ megan = Backframe::Fixtures::Contact.create(first_name: 'Megan', last_name: 'Pugh', email: 'megan@thinktopography.com', photo: megan_photo)
11
+ kath = Backframe::Fixtures::Contact.create(first_name: 'Kath', last_name: 'Tibbetts', email: 'kath@thinktopography.com', photo: kath_photo)
12
+ armand = Backframe::Fixtures::Contact.create(first_name: 'Armand', last_name: 'Zerilli', email: 'armand@thinktopography.com', photo: armand_photo)
@@ -0,0 +1,23 @@
1
+ require 'active_model_serializers'
2
+
3
+ module Backframe
4
+
5
+ module Fixtures
6
+
7
+ class ContactSerializer < ActiveModel::Serializer
8
+
9
+ attributes :id, :first_name, :last_name, :email
10
+
11
+ belongs_to :photo
12
+
13
+ end
14
+
15
+ class PhotoSerializer < ActiveModel::Serializer
16
+
17
+ attributes :id, :path
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'backframe'
2
+
3
+ module Backframe
4
+
5
+ module Fixtures
6
+
7
+ class CreateContactService < Backframe::Service
8
+
9
+ def initialize(params)
10
+ @params = params
11
+ end
12
+
13
+ def perform
14
+ create_contact
15
+ { contact: @contact }
16
+ end
17
+
18
+ def create_contact
19
+ @contact = Contact.create!(@params)
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Backframe::Query::Sort do
4
+
5
+ it 'returns the default sort order' do
6
+ actual = Backframe::Query::Sort.parse()
7
+ expected = [
8
+ { key: 'created_at', order: 'DESC' },
9
+ ]
10
+ expect(actual).to eq(expected)
11
+ end
12
+
13
+ it 'returns a simple asecnding sort order' do
14
+ actual = Backframe::Query::Sort.parse('first_name')
15
+ expected = [
16
+ { key: 'first_name', order: 'ASC' },
17
+ ]
18
+ expect(actual).to eq(expected)
19
+ end
20
+
21
+ it 'returns a simple desecnding sort order' do
22
+ actual = Backframe::Query::Sort.parse('-first_name')
23
+ expected = [
24
+ { key: 'first_name', order: 'DESC' },
25
+ ]
26
+ expect(actual).to eq(expected)
27
+ end
28
+
29
+ it 'returns a complex mixed sort order' do
30
+ actual = Backframe::Query::Sort.parse('first_name,-last_name')
31
+ expected = [
32
+ { key: 'first_name', order: 'ASC' },
33
+ { key: 'last_name', order: 'DESC' }
34
+ ]
35
+ expect(actual).to eq(expected)
36
+ end
37
+
38
+ it 'doesnt care about spaces' do
39
+ actual = Backframe::Query::Sort.parse(' first_name , last_name ')
40
+ expected = [
41
+ { key: 'first_name', order: 'ASC' },
42
+ { key: 'last_name', order: 'ASC' }
43
+ ]
44
+ expect(actual).to eq(expected)
45
+ end
46
+
47
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Backframe::Query do
4
+
5
+ before(:all) do
6
+ @contact = Backframe::Fixtures::Contact
7
+ @greg = @contact.find(1)
8
+ @megan = @contact.find(2)
9
+ @kath = @contact.find(3)
10
+ @armand = @contact.find(4)
11
+ end
12
+
13
+ it 'return no filtering as the default' do
14
+ records = Backframe::Query.perform(@contact, {})
15
+ expect(records).to eq(@contact)
16
+ end
17
+
18
+ it 'can filter' do
19
+ records = Backframe::Fixtures::ContactQuery.perform(@contact, { first_name: 'Greg' })
20
+ expect(records.count).to eq(1)
21
+ expect(records.first.id).to eq(@greg.id)
22
+ end
23
+
24
+ it 'can sort on a single field ascending' do
25
+ records = Backframe::Fixtures::ContactQuery.perform(@contact, { sort: 'created_at' })
26
+ expect(records.first.id).to eq(@greg.id)
27
+ end
28
+
29
+ it 'can sort on a single field descending' do
30
+ records = Backframe::Fixtures::ContactQuery.perform(@contact, { sort: '-created_at' })
31
+ expect(records.first.id).to eq(@armand.id)
32
+ end
33
+
34
+ # it 'can sort on multiple fields with mixed order' do
35
+ # post = Backframe::Fixtures::Post
36
+ # records = Backframe::Fixtures::PostQuery.perform(post, { sort: '-last_name,created_at' })
37
+ # expect(records[0].id).to eq(@post3.id)
38
+ # expect(records[1].id).to eq(@post1.id)
39
+ # expect(records[2].id).to eq(@post2.id)
40
+ # end
41
+
42
+ it 'ignore invalid sort' do
43
+ records = Backframe::Fixtures::ContactQuery.perform(@contact, { sort: '123^' })
44
+ ids = records.all.map { |r| r.id }
45
+ expect(ids).to eq([1,2,3,4])
46
+ end
47
+
48
+ it 'can exclude_ids' do
49
+ records = Backframe::Fixtures::ContactQuery.perform(@contact, { exclude_ids: '1,2' })
50
+ ids = records.all.map { |r| r.id }
51
+ expect(ids).not_to include(1)
52
+ expect(ids).not_to include(2)
53
+ expect(ids).to include(3)
54
+ expect(ids).to include(4)
55
+ end
56
+
57
+ it 'ignore invalid exclude_ids' do
58
+ records = Backframe::Fixtures::ContactQuery.perform(@contact, { exclude_ids: '1,b,c' })
59
+ ids = records.all.map { |r| r.id }
60
+ expect(ids).to eq([1,2,3,4])
61
+ end
62
+
63
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe Backframe::Response::Adapter::Csv do
4
+
5
+ it 'renders full payload' do
6
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
7
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
8
+ actual = Backframe::Response::Adapter::Csv.render(collection, fields)
9
+ expected = [
10
+ 'id,first_name,last_name,email,photo.id,photo.path',
11
+ '1,Greg,Kops,greg@thinktopography.com,1,/images/greg.jpg',
12
+ '2,Megan,Pugh,megan@thinktopography.com,2,/images/megan.jpg',
13
+ '3,Kath,Tibbetts,kath@thinktopography.com,3,/images/kath.jpg',
14
+ '4,Armand,Zerilli,armand@thinktopography.com,4,/images/armand.jpg'
15
+ ].join("\n")
16
+ expect(actual).to eq(expected)
17
+ end
18
+
19
+ it 'renders with a single simple key' do
20
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
21
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'first_name')
22
+ actual = Backframe::Response::Adapter::Csv.render(collection, fields)
23
+ expected = ['first_name','Greg','Megan','Kath','Armand'].join("\n")
24
+ expect(actual).to eq(expected)
25
+ end
26
+
27
+ it 'renders with a single nested key' do
28
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
29
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'photo.id')
30
+ actual = Backframe::Response::Adapter::Csv.render(collection, fields)
31
+ expected = ['photo.id','1','2','3','4'].join("\n")
32
+ expect(actual).to eq(expected)
33
+ end
34
+
35
+ it 'renders with pagination' do
36
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, 1, 2)
37
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
38
+ actual = Backframe::Response::Adapter::Csv.render(collection, fields)
39
+ expected = [
40
+ 'id,first_name,last_name,email,photo.id,photo.path',
41
+ '1,Greg,Kops,greg@thinktopography.com,1,/images/greg.jpg',
42
+ '2,Megan,Pugh,megan@thinktopography.com,2,/images/megan.jpg'
43
+ ].join("\n")
44
+ expect(actual).to eq(expected)
45
+ end
46
+
47
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Backframe::Response::Adapter::Json do
4
+
5
+ before(:all) do
6
+ @records = [
7
+ { id: 1, first_name: 'Greg', last_name: 'Kops', email: 'greg@thinktopography.com', photo: { id: 1, path: '/images/greg.jpg' } },
8
+ { id: 2, first_name: 'Megan', last_name: 'Pugh', email: 'megan@thinktopography.com', photo: { id: 2, path: '/images/megan.jpg' } },
9
+ { id: 3, first_name: 'Kath', last_name: 'Tibbetts', email: 'kath@thinktopography.com', photo: { id: 3, path: '/images/kath.jpg' } },
10
+ { id: 4, first_name: 'Armand', last_name: 'Zerilli', email: 'armand@thinktopography.com', photo: { id: 4, path: '/images/armand.jpg' } }
11
+ ]
12
+ end
13
+
14
+ it 'renders full payload' do
15
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
16
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
17
+ actual = Backframe::Response::Adapter::Json.render(collection, fields)
18
+ expected = {
19
+ records: @records,
20
+ total_records: 4,
21
+ current_page: 1,
22
+ total_pages: 1
23
+ }
24
+ expect(actual).to eq(expected)
25
+ end
26
+
27
+ it 'renders with a single simple key' do
28
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
29
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'first_name')
30
+ actual = Backframe::Response::Adapter::Json.render(collection, fields)
31
+ expected = {
32
+ records: @records.map { |r| { first_name: r[:first_name] } },
33
+ total_records: 4,
34
+ current_page: 1,
35
+ total_pages: 1
36
+ }
37
+ expect(actual).to eq(expected)
38
+ end
39
+
40
+ it 'renders with a single nested key' do
41
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
42
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'photo.id')
43
+ actual = Backframe::Response::Adapter::Json.render(collection, fields)
44
+ expected = {
45
+ records: @records.map { |r| { photo: { id: r[:photo][:id] } } },
46
+ total_records: 4,
47
+ current_page: 1,
48
+ total_pages: 1
49
+ }
50
+ expect(actual).to eq(expected)
51
+ end
52
+
53
+ it 'renders with pagination' do
54
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, 1, 2)
55
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
56
+ actual = Backframe::Response::Adapter::Json.render(collection, fields)
57
+ expected = {
58
+ records: @records[0, 2],
59
+ total_records: 4,
60
+ current_page: 1,
61
+ total_pages: 2
62
+ }
63
+ expect(actual).to eq(expected)
64
+ end
65
+
66
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Backframe::Response::Adapter::Xlsx do
4
+
5
+ it 'renders full payload' do
6
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
7
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
8
+ actual = Backframe::Response::Adapter::Xlsx.render(collection, fields)
9
+ File.open('tmp.xlsx', 'w') { |file| file.write(actual) }
10
+ xlsx = Roo::Excelx.new('tmp.xlsx')
11
+ expect(xlsx.sheet(0).row(1)).to eq(["id", "first_name", "last_name", "email", "photo.id", "photo.path"])
12
+ expect(xlsx.sheet(0).row(2)).to eq(["1", "Greg", "Kops", "greg@thinktopography.com", "1", "/images/greg.jpg"])
13
+ expect(xlsx.sheet(0).row(3)).to eq(["2", "Megan", "Pugh", "megan@thinktopography.com", "2", "/images/megan.jpg"])
14
+ expect(xlsx.sheet(0).row(4)).to eq(["3", "Kath", "Tibbetts", "kath@thinktopography.com", "3", "/images/kath.jpg"])
15
+ expect(xlsx.sheet(0).row(5)).to eq(["4", "Armand", "Zerilli", "armand@thinktopography.com", "4", "/images/armand.jpg"])
16
+ File.unlink('tmp.xlsx')
17
+ end
18
+
19
+ it 'renders with a single simple key' do
20
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
21
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'first_name')
22
+ actual = Backframe::Response::Adapter::Xlsx.render(collection, fields)
23
+ File.open('tmp.xlsx', 'w') { |file| file.write(actual) }
24
+ xlsx = Roo::Excelx.new('tmp.xlsx')
25
+ expect(xlsx.sheet(0).row(1)).to eq(["first_name"])
26
+ expect(xlsx.sheet(0).row(2)).to eq(["Greg"])
27
+ expect(xlsx.sheet(0).row(3)).to eq(["Megan"])
28
+ expect(xlsx.sheet(0).row(4)).to eq(["Kath"])
29
+ expect(xlsx.sheet(0).row(5)).to eq(["Armand"])
30
+ File.unlink('tmp.xlsx')
31
+ end
32
+
33
+ it 'renders with a single nested key' do
34
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
35
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'photo.id')
36
+ actual = Backframe::Response::Adapter::Xlsx.render(collection, fields)
37
+ File.open('tmp.xlsx', 'w') { |file| file.write(actual) }
38
+ xlsx = Roo::Excelx.new('tmp.xlsx')
39
+ expect(xlsx.sheet(0).row(1)).to eq(["photo.id"])
40
+ expect(xlsx.sheet(0).row(2)).to eq(["1"])
41
+ expect(xlsx.sheet(0).row(3)).to eq(["2"])
42
+ expect(xlsx.sheet(0).row(4)).to eq(["3"])
43
+ expect(xlsx.sheet(0).row(5)).to eq(["4"])
44
+ File.unlink('tmp.xlsx')
45
+ end
46
+
47
+ it 'renders with pagination' do
48
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, 1, 2)
49
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
50
+ actual = Backframe::Response::Adapter::Xlsx.render(collection, fields)
51
+ File.open('tmp.xlsx', 'w') { |file| file.write(actual) }
52
+ xlsx = Roo::Excelx.new('tmp.xlsx')
53
+ expect(xlsx.sheet(0).row(1)).to eq(["id", "first_name", "last_name", "email", "photo.id", "photo.path"])
54
+ expect(xlsx.sheet(0).row(2)).to eq(["1", "Greg", "Kops", "greg@thinktopography.com", "1", "/images/greg.jpg"])
55
+ expect(xlsx.sheet(0).row(3)).to eq(["2", "Megan", "Pugh", "megan@thinktopography.com", "2", "/images/megan.jpg"])
56
+ File.unlink('tmp.xlsx')
57
+ end
58
+
59
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe Backframe::Response::Adapter::Xml do
4
+
5
+ it 'renders full payload' do
6
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
7
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
8
+ actual = Backframe::Response::Adapter::Xml.render(collection, fields)
9
+ expected = [
10
+ '<?xml version="1.0"?><records>',
11
+ '<record><id>1</id><first_name>Greg</first_name><last_name>Kops</last_name><email>greg@thinktopography.com</email><photo.id>1</photo.id><photo.path>/images/greg.jpg</photo.path></record>',
12
+ '<record><id>2</id><first_name>Megan</first_name><last_name>Pugh</last_name><email>megan@thinktopography.com</email><photo.id>2</photo.id><photo.path>/images/megan.jpg</photo.path></record>',
13
+ '<record><id>3</id><first_name>Kath</first_name><last_name>Tibbetts</last_name><email>kath@thinktopography.com</email><photo.id>3</photo.id><photo.path>/images/kath.jpg</photo.path></record>',
14
+ '<record><id>4</id><first_name>Armand</first_name><last_name>Zerilli</last_name><email>armand@thinktopography.com</email><photo.id>4</photo.id><photo.path>/images/armand.jpg</photo.path></record>',
15
+ '</records>'
16
+ ].join
17
+ expect(actual).to eq(expected)
18
+ end
19
+
20
+ it 'renders with a single simple key' do
21
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
22
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'first_name')
23
+ actual = Backframe::Response::Adapter::Xml.render(collection, fields)
24
+ expected = [
25
+ '<?xml version="1.0"?><records>',
26
+ '<record><first_name>Greg</first_name></record>',
27
+ '<record><first_name>Megan</first_name></record>',
28
+ '<record><first_name>Kath</first_name></record>',
29
+ '<record><first_name>Armand</first_name></record>',
30
+ '</records>'
31
+ ].join
32
+ expect(actual).to eq(expected)
33
+ end
34
+
35
+ it 'renders with a single nested key' do
36
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, nil, nil)
37
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, 'photo.id')
38
+ actual = Backframe::Response::Adapter::Xml.render(collection, fields)
39
+ expected = [
40
+ '<?xml version="1.0"?><records>',
41
+ '<record><photo.id>1</photo.id></record>',
42
+ '<record><photo.id>2</photo.id></record>',
43
+ '<record><photo.id>3</photo.id></record>',
44
+ '<record><photo.id>4</photo.id></record>',
45
+ '</records>'
46
+ ].join
47
+ expect(actual).to eq(expected)
48
+ end
49
+
50
+ it 'renders with pagination' do
51
+ collection = Backframe::Response::Collection.new(Backframe::Fixtures::Contact, 1, 2)
52
+ fields = Backframe::Response::Fields.new(Backframe::Fixtures::Contact, nil)
53
+ actual = Backframe::Response::Adapter::Xml.render(collection, fields)
54
+ expected = [
55
+ '<?xml version="1.0"?><records>',
56
+ '<record><id>1</id><first_name>Greg</first_name><last_name>Kops</last_name><email>greg@thinktopography.com</email><photo.id>1</photo.id><photo.path>/images/greg.jpg</photo.path></record>',
57
+ '<record><id>2</id><first_name>Megan</first_name><last_name>Pugh</last_name><email>megan@thinktopography.com</email><photo.id>2</photo.id><photo.path>/images/megan.jpg</photo.path></record>',
58
+ '</records>'
59
+ ].join
60
+ expect(actual).to eq(expected)
61
+ end
62
+
63
+ end