moblues 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -5
  3. data/lib/moblues/cli.rb +3 -4
  4. data/lib/moblues/generator/base/model.rb +24 -0
  5. data/lib/moblues/generator/base/type.rb +63 -0
  6. data/lib/moblues/generator/objc/base.rb +67 -0
  7. data/lib/moblues/generator/objc/human.rb +27 -0
  8. data/lib/moblues/generator/{human_header.h.erb → objc/human_header.h.erb} +0 -0
  9. data/lib/moblues/generator/{human_implementation.m.erb → objc/human_implementation.m.erb} +0 -0
  10. data/lib/moblues/generator/objc/machine.rb +31 -0
  11. data/lib/moblues/generator/{machine_header.h.erb → objc/machine_header.h.erb} +2 -2
  12. data/lib/moblues/generator/{machine_implementation.m.erb → objc/machine_implementation.m.erb} +0 -0
  13. data/lib/moblues/generator/objc/type.rb +24 -0
  14. data/lib/moblues/generator/swift/base.rb +39 -0
  15. data/lib/moblues/generator/swift/human.rb +18 -0
  16. data/lib/moblues/generator/swift/human.swift.erb +4 -0
  17. data/lib/moblues/generator/swift/machine.rb +18 -0
  18. data/lib/moblues/generator/swift/machine.swift.erb +12 -0
  19. data/lib/moblues/generator.rb +9 -4
  20. data/lib/moblues/reader/type.rb +3 -37
  21. data/lib/moblues/version.rb +1 -1
  22. data/lib/moblues.rb +20 -4
  23. data/spec/features/moblues_spec.rb +35 -16
  24. data/spec/lib/moblues/cli_spec.rb +12 -2
  25. data/spec/lib/moblues/generator/base/model_spec.rb +27 -0
  26. data/spec/lib/moblues/generator/base/type_spec.rb +46 -0
  27. data/spec/lib/moblues/generator/objc/human_spec.rb +54 -0
  28. data/spec/lib/moblues/generator/{machine_spec.rb → objc/machine_spec.rb} +9 -8
  29. data/spec/lib/moblues/generator/objc/type_spec.rb +23 -0
  30. data/spec/lib/moblues/generator/swift/human_spec.rb +34 -0
  31. data/spec/lib/moblues/generator/swift/machine_spec.rb +57 -0
  32. data/spec/lib/moblues/reader/type_spec.rb +3 -54
  33. data/spec/moblues_spec.rb +46 -12
  34. data/spec/resources/expected/{Author.h → objc/Author.h} +0 -0
  35. data/spec/resources/expected/{Author.m → objc/Author.m} +0 -0
  36. data/spec/resources/expected/{_Author.h → objc/_Author.h} +0 -0
  37. data/spec/resources/expected/{_Author.m → objc/_Author.m} +0 -0
  38. data/spec/resources/expected/{_Book.h → objc/_Book.h} +0 -0
  39. data/spec/resources/expected/{_Book.m → objc/_Book.m} +0 -0
  40. data/spec/resources/expected/{_Person.h → objc/_Person.h} +0 -0
  41. data/spec/resources/expected/{_Person.m → objc/_Person.m} +0 -0
  42. data/spec/resources/expected/{_Team.h → objc/_Team.h} +0 -0
  43. data/spec/resources/expected/{_Team.m → objc/_Team.m} +0 -0
  44. data/spec/resources/expected/{human → objc/human}/Playable.h +0 -0
  45. data/spec/resources/expected/{human → objc/human}/Playable.m +0 -0
  46. data/spec/resources/expected/{human → objc/human}/Playlist.h +0 -0
  47. data/spec/resources/expected/{human → objc/human}/Playlist.m +0 -0
  48. data/spec/resources/expected/{human → objc/human}/Track.h +0 -0
  49. data/spec/resources/expected/{human → objc/human}/Track.m +0 -0
  50. data/spec/resources/expected/{human → objc/human}/User.h +0 -0
  51. data/spec/resources/expected/{human → objc/human}/User.m +0 -0
  52. data/spec/resources/expected/{machine → objc/machine}/_Playable.h +0 -0
  53. data/spec/resources/expected/{machine → objc/machine}/_Playable.m +0 -0
  54. data/spec/resources/expected/{machine → objc/machine}/_Playlist.h +0 -0
  55. data/spec/resources/expected/{machine → objc/machine}/_Playlist.m +0 -0
  56. data/spec/resources/expected/{machine → objc/machine}/_Track.h +0 -0
  57. data/spec/resources/expected/{machine → objc/machine}/_Track.m +0 -0
  58. data/spec/resources/expected/{machine → objc/machine}/_User.h +0 -0
  59. data/spec/resources/expected/{machine → objc/machine}/_User.m +0 -0
  60. data/spec/resources/expected/swift/Author.swift +4 -0
  61. data/spec/resources/expected/swift/_Author.swift +11 -0
  62. data/spec/resources/expected/swift/_Book.swift +8 -0
  63. data/spec/resources/expected/swift/human/Playable.swift +4 -0
  64. data/spec/resources/expected/swift/human/Playlist.swift +5 -0
  65. data/spec/resources/expected/swift/human/Track.swift +4 -0
  66. data/spec/resources/expected/swift/human/User.swift +4 -0
  67. data/spec/resources/expected/swift/machine/_Playable.swift +8 -0
  68. data/spec/resources/expected/swift/machine/_Playlist.swift +8 -0
  69. data/spec/resources/expected/swift/machine/_Track.swift +9 -0
  70. data/spec/resources/expected/swift/machine/_User.swift +10 -0
  71. data/spec/resources/factories/data_model/attribute_factory.rb +28 -0
  72. data/spec/resources/factories/data_model/relationship_factory.rb +15 -0
  73. data/spec/resources/fixtures.rb +10 -10
  74. data/spec/resources/tmp/{human → objc/human}/Playlist.h +0 -0
  75. data/spec/resources/tmp/{human → objc/human}/Playlist.m +0 -0
  76. data/spec/resources/tmp/swift/.gitkeep +0 -0
  77. data/spec/resources/tmp/swift/human/Playlist.swift +5 -0
  78. metadata +113 -76
  79. data/lib/moblues/generator/base.rb +0 -65
  80. data/lib/moblues/generator/human.rb +0 -25
  81. data/lib/moblues/generator/machine.rb +0 -36
  82. data/lib/moblues/generator/model.rb +0 -23
  83. data/spec/lib/moblues/generator/human_spec.rb +0 -74
  84. data/spec/lib/moblues/generator/model_spec.rb +0 -27
  85. data/spec/resources/tmp/_Team.h +0 -18
  86. data/spec/resources/tmp/_Team.m +0 -5
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'moblues/generator/base/type'
3
+
4
+ describe Moblues::Generator::Base::Type do
5
+ shared_examples_for 'attribute_type' do |attribute, expected|
6
+ it "returns #{expected} for #{attribute.type}" do
7
+ expect(subject.attribute_type(attribute)).to eq(expected)
8
+ end
9
+ end
10
+
11
+ shared_examples_for 'relationship_type' do |relationship, expected|
12
+ it "returns #{expected} for #{relationship}" do
13
+ expect(subject.relationship_type(relationship)).to eq(expected)
14
+ end
15
+ end
16
+
17
+ context 'SWIFT' do
18
+ subject { described_class.new(Moblues::Generator::Base::Type::SWIFT) }
19
+
20
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :string), 'String'
21
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :number), 'NSNumber'
22
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :decimal), 'NSDecimalNumber'
23
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :date), 'NSDate'
24
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :data), 'NSData'
25
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :id), 'AnyObject'
26
+
27
+ it_behaves_like 'relationship_type', FactoryGirl.build(:relationship, :single), 'DestinationEntity'
28
+ it_behaves_like 'relationship_type', FactoryGirl.build(:relationship, :to_many), 'NSSet'
29
+ it_behaves_like 'relationship_type', FactoryGirl.build(:relationship, :to_many_ordered), 'NSOrderedSet'
30
+ end
31
+
32
+ context 'OBJC' do
33
+ subject { described_class.new(Moblues::Generator::Base::Type::OBJC) }
34
+
35
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :string), 'NSString *'
36
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :number), 'NSNumber *'
37
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :decimal), 'NSDecimalNumber *'
38
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :date), 'NSDate *'
39
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :data), 'NSData *'
40
+ it_behaves_like 'attribute_type', FactoryGirl.build(:attribute, :id), 'id '
41
+
42
+ it_behaves_like 'relationship_type', FactoryGirl.build(:relationship, :single), 'DestinationEntity *'
43
+ it_behaves_like 'relationship_type', FactoryGirl.build(:relationship, :to_many), 'NSSet *'
44
+ it_behaves_like 'relationship_type', FactoryGirl.build(:relationship, :to_many_ordered), 'NSOrderedSet *'
45
+ end
46
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'moblues/generator/objc/human'
3
+ require 'moblues/data_model'
4
+
5
+ describe Moblues::Generator::Objc::Human do
6
+ let(:entity) { Moblues::DataModel::Entity.new(name: 'Author') }
7
+ let(:output_dir) { Fixtures.generated_dir(:objc) }
8
+
9
+ after do
10
+ Fixtures.delete_tmp_files(%w{Author.h Author.m}, :objc)
11
+ end
12
+
13
+ describe '#generate' do
14
+ it 'generates a human header' do
15
+ subject.generate(output_dir, entity)
16
+
17
+ expect(Fixtures.generated_file_content('Author.h', :objc)).to eq(Fixtures.expected_content('Author.h', :objc))
18
+ end
19
+
20
+ it 'generates a human implementation' do
21
+ subject.generate(output_dir, entity)
22
+
23
+ expect(Fixtures.generated_file_content('Author.m', :objc)).to eq(Fixtures.expected_content('Author.m', :objc))
24
+ end
25
+
26
+ context 'if the header already exists' do
27
+ before do
28
+ File.open(File.join(Fixtures.generated_dir(:objc), 'Author.h'), 'w+') do |f|
29
+ f.write('do nothing')
30
+ end
31
+ end
32
+
33
+ it 'does not overwrite the header file' do
34
+ subject.generate(output_dir, entity)
35
+
36
+ expect(Fixtures.generated_file_content('Author.h', :objc)).to eq('do nothing')
37
+ end
38
+ end
39
+
40
+ context 'if the implementation already exists' do
41
+ before do
42
+ File.open(File.join(Fixtures.generated_dir(:objc), 'Author.m'), 'w+') do |f|
43
+ f.write('do nothing')
44
+ end
45
+ end
46
+
47
+ it 'does not overwrite the implementation file' do
48
+ subject.generate(output_dir, entity)
49
+
50
+ expect(Fixtures.generated_file_content('Author.m', :objc)).to eq('do nothing')
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,26 +1,27 @@
1
1
  require 'spec_helper'
2
- require 'moblues/generator/machine'
2
+ require 'moblues/generator/objc/machine'
3
3
  require 'moblues/data_model'
4
4
 
5
- describe Moblues::Generator::Machine do
6
- subject { described_class.new(output_dir: Fixtures.generated_dir) }
5
+ describe Moblues::Generator::Objc::Machine do
6
+ let(:output_dir) { Fixtures.generated_dir(:objc) }
7
7
 
8
8
  after do
9
- Fixtures.delete_tmp_files(%w{_Author.h _Author.m _Person.h _Person.m _Book.h _Book.m})
9
+ tmp_files = %w{Author Person Book Team}.map { |klass| %W{_#{klass}.h _#{klass}.m} }.flatten
10
+ Fixtures.delete_tmp_files(tmp_files, :objc)
10
11
  end
11
12
 
12
13
  describe '#generate' do
13
14
  shared_examples_for 'machine_generator' do |name|
14
15
  it 'generates a header' do
15
- subject.generate(entity)
16
+ subject.generate(output_dir, entity)
16
17
 
17
- expect(Fixtures.generated_file_content(header(name))).to eq(Fixtures.expected_content(header(name)))
18
+ expect(Fixtures.generated_file_content(header(name), :objc)).to eq(Fixtures.expected_content(header(name), :objc))
18
19
  end
19
20
 
20
21
  it 'generates an implementation' do
21
- subject.generate(entity)
22
+ subject.generate(output_dir, entity)
22
23
 
23
- expect(Fixtures.generated_file_content(implementation(name))).to eq(Fixtures.expected_content(implementation(name)))
24
+ expect(Fixtures.generated_file_content(implementation(name), :objc)).to eq(Fixtures.expected_content(implementation(name), :objc))
24
25
  end
25
26
  end
26
27
 
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'moblues/generator/objc/type'
3
+
4
+ describe Moblues::Generator::Objc::Type do
5
+ describe '#property_attributes' do
6
+ shared_examples_for 'property_attributes' do |attribute, expected|
7
+ it "returns #{expected} for #{attribute.type}" do
8
+ expect(subject.property_attributes(attribute)).to eq(expected)
9
+ end
10
+ end
11
+
12
+ it_behaves_like 'property_attributes', FactoryGirl.build(:attribute, :string), %w(nonatomic copy)
13
+ it_behaves_like 'property_attributes', FactoryGirl.build(:attribute, :number), %w(nonatomic strong)
14
+ it_behaves_like 'property_attributes', FactoryGirl.build(:attribute, :decimal), %w(nonatomic strong)
15
+ it_behaves_like 'property_attributes', FactoryGirl.build(:attribute, :date), %w(nonatomic strong)
16
+ it_behaves_like 'property_attributes', FactoryGirl.build(:attribute, :data), %w(nonatomic strong)
17
+ it_behaves_like 'property_attributes', FactoryGirl.build(:attribute, :id), %w(nonatomic strong)
18
+
19
+ it 'raises ArgumentError when the type is unknown' do
20
+ expect { subject.property_attributes(FactoryGirl.build(:attribute, :unknown)) }.to raise_exception
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'moblues/generator/swift/human'
3
+
4
+ describe Moblues::Generator::Swift::Human do
5
+ let(:output_dir) { Fixtures.generated_dir(:swift) }
6
+
7
+ let(:entity) { Moblues::DataModel::Entity.new(name: 'Author') }
8
+
9
+ after do
10
+ Fixtures.delete_tmp_files(%w{Author.swift}, :swift)
11
+ end
12
+
13
+ describe '#generate' do
14
+ it 'generates a human file' do
15
+ subject.generate(output_dir, entity)
16
+
17
+ expect(Fixtures.generated_file_content('Author.swift', :swift)).to eq(Fixtures.expected_content('Author.swift', :swift))
18
+ end
19
+
20
+ context 'if the file already exists' do
21
+ before do
22
+ File.open(File.join(Fixtures.generated_dir(:swift), 'Author.swift'), 'w+') do |f|
23
+ f.write('do nothing')
24
+ end
25
+ end
26
+
27
+ it 'does not overwrite the it' do
28
+ subject.generate(output_dir, entity)
29
+
30
+ expect(Fixtures.generated_file_content('Author.swift', :swift)).to eq('do nothing')
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'moblues/generator/swift/machine'
3
+
4
+ describe Moblues::Generator::Swift::Machine do
5
+ let(:output_dir) { Fixtures.generated_dir(:swift) }
6
+
7
+ after do
8
+ tmp_files = %w{Author Book}.map { |klass| "_#{klass}.swift" }
9
+ Fixtures.delete_tmp_files(tmp_files, :swift)
10
+ end
11
+
12
+ describe '#generate' do
13
+ shared_examples_for 'machine_generator' do |name|
14
+ it 'generates a swift file' do
15
+ subject.generate(output_dir, entity)
16
+
17
+ expect(Fixtures.generated_file_content(file(name), :swift)).to eq(Fixtures.expected_content(file(name), :swift))
18
+ end
19
+ end
20
+
21
+ context 'with a complex entity' do
22
+ let(:entity) { Moblues::DataModel::Entity.new(name: 'Author',
23
+ parent_entity: 'Person',
24
+ attributes: attributes,
25
+ relationships: relationships) }
26
+ let(:attributes) {[
27
+ Moblues::DataModel::Attribute.new(name: 'dob', type: :date),
28
+ Moblues::DataModel::Attribute.new(name: 'name', type: :string)
29
+ ]}
30
+ let(:relationships) {[
31
+ Moblues::DataModel::Relationship.new(name: 'books', destination_entity: 'Book', to_many: true, ordered: true),
32
+ Moblues::DataModel::Relationship.new(name: 'essays', destination_entity: 'Book', to_many: true),
33
+ Moblues::DataModel::Relationship.new(name: 'publisher', destination_entity: 'Publisher')
34
+ ]}
35
+
36
+ it_behaves_like 'machine_generator', 'Author'
37
+ end
38
+
39
+ context 'with a simple entity' do
40
+ let(:entity) { Moblues::DataModel::Entity.new(name: 'Book',
41
+ attributes: attributes,
42
+ relationships: relationships) }
43
+ let(:attributes) {[
44
+ Moblues::DataModel::Attribute.new(name: 'name', type: :string)
45
+ ]}
46
+ let(:relationships) {[
47
+ Moblues::DataModel::Relationship.new(name: 'editions', destination_entity: 'Edition', to_many: true)
48
+ ]}
49
+
50
+ it_behaves_like 'machine_generator', 'Book'
51
+ end
52
+ end
53
+
54
+ def file(name)
55
+ "_#{name}.swift"
56
+ end
57
+ end
@@ -14,6 +14,9 @@ describe Moblues::Reader::Type do
14
14
  it_behaves_like 'map_type_str', 'Integer 32', :number
15
15
  it_behaves_like 'map_type_str', 'Integer 64', :number
16
16
  it_behaves_like 'map_type_str', 'Boolean', :number
17
+ it_behaves_like 'map_type_str', 'Float', :number
18
+ it_behaves_like 'map_type_str', 'Double', :number
19
+ it_behaves_like 'map_type_str', 'Decimal', :decimal
17
20
  it_behaves_like 'map_type_str', 'Date', :date
18
21
  it_behaves_like 'map_type_str', 'Binary', :data
19
22
  it_behaves_like 'map_type_str', 'Transformable', :id
@@ -22,58 +25,4 @@ describe Moblues::Reader::Type do
22
25
  expect { subject.map_type_str('Unknown Type') }.to raise_exception(ArgumentError)
23
26
  end
24
27
  end
25
-
26
- describe '#property_type' do
27
- shared_examples 'property_type' do |type, property_type|
28
- it "returns #{property_type} for #{type}" do
29
- expect(subject.property_type(type)).to eq(property_type)
30
- end
31
- end
32
-
33
- it_behaves_like 'property_type', :string, 'NSString *'
34
- it_behaves_like 'property_type', :number, 'NSNumber *'
35
- it_behaves_like 'property_type', :date, 'NSDate *'
36
- it_behaves_like 'property_type', :data, 'NSData *'
37
- it_behaves_like 'property_type', :id, 'id '
38
-
39
- it 'raises an exception when the type is unknown' do
40
- expect { subject.property_type(:unknown) }.to raise_exception(ArgumentError)
41
- end
42
- end
43
-
44
- describe '#property_attributes' do
45
- shared_examples 'property_attributes' do |type, attrs|
46
- it "returns #{attrs} for #{type}" do
47
- expect(subject.property_attributes(type)).to eq(attrs)
48
- end
49
- end
50
-
51
- it_behaves_like 'property_attributes', :string, %w(nonatomic copy)
52
- it_behaves_like 'property_attributes', :number, %w(nonatomic strong)
53
- it_behaves_like 'property_attributes', :date, %w(nonatomic strong)
54
- it_behaves_like 'property_attributes', :data, %w(nonatomic strong)
55
- it_behaves_like 'property_attributes', :id, %w(nonatomic strong)
56
-
57
- it 'raises an exception when the type is unknown' do
58
- expect { subject.property_attributes(:unknown) }.to raise_exception(ArgumentError)
59
- end
60
- end
61
-
62
- describe '#relationship_type' do
63
- shared_examples 'relationship_type' do |rel, type|
64
- it "returns #{type} for #{rel}" do
65
- expect(subject.relationship_type(rel)).to eq(type)
66
- end
67
- end
68
-
69
- it_behaves_like 'relationship_type',
70
- Moblues::DataModel::Relationship.new(name: '', destination_entity: 'Dest'),
71
- 'Dest *'
72
- it_behaves_like 'relationship_type',
73
- Moblues::DataModel::Relationship.new(name: '', destination_entity: 'Dest', to_many: true),
74
- 'NSSet *'
75
- it_behaves_like 'relationship_type',
76
- Moblues::DataModel::Relationship.new(name: '', destination_entity: 'Dest', to_many: true, ordered: true),
77
- 'NSOrderedSet *'
78
- end
79
28
  end
data/spec/moblues_spec.rb CHANGED
@@ -5,28 +5,62 @@ describe Moblues do
5
5
  subject { described_class }
6
6
 
7
7
  describe '#generate' do
8
- let(:options) { %w{--model=model/path --human=human/path --machine=machine/path} }
9
-
10
8
  let(:model) { 'model/path' }
11
- let(:human) { 'human/path' }
12
- let(:machine) { 'machine/path' }
9
+ let(:human_dir) { 'human/path' }
10
+ let(:machine_dir) { 'machine/path' }
11
+
12
+ let(:human) { nil }
13
+ let(:machine) { nil }
14
+ let(:params) { { human_dir: human_dir, machine_dir: machine_dir, human: human, machine: machine} }
13
15
 
14
16
  let(:model_reader) { double(Moblues::Reader::Model) }
15
- let(:model_generator) { double(Moblues::Generator::Model) }
17
+ let(:model_generator) { double(Moblues::Generator::Base::Model) }
16
18
  let(:entities) { [build(:entity)] }
17
19
 
18
20
  before do
19
21
  allow(Moblues::Reader::Model).to receive(:new) { model_reader }
20
- allow(Moblues::Generator::Model).to receive(:new) { model_generator }
22
+ allow(Moblues::Generator::Base::Model).to receive(:new).with(params) { model_generator }
23
+ end
24
+
25
+ shared_examples_for 'generate' do |lang|
26
+ it 'creates the directories reads the model and generates the files' do
27
+ expect(Dir).to receive(:mkdir).with('human/path').once
28
+ expect(Dir).to receive(:mkdir).with('machine/path').once
29
+ expect(model_reader).to receive(:model).with('model/path').once { entities }
30
+ expect(model_generator).to receive(:generate).with(entities).once
31
+
32
+ subject.generate(model, human_dir, machine_dir, lang)
33
+ end
34
+ end
35
+
36
+ context 'when lang is swift' do
37
+ let(:human) { double(Moblues::Generator::Swift::Human) }
38
+ let(:machine) { double(Moblues::Generator::Swift::Machine) }
39
+
40
+ before do
41
+ allow(Moblues::Generator::Swift::Human).to receive(:new) { human }
42
+ allow(Moblues::Generator::Swift::Machine).to receive(:new) { machine }
43
+ end
44
+
45
+ it_behaves_like 'generate', :swift
21
46
  end
22
47
 
23
- it 'created the directories reads the model and generates the files' do
24
- expect(Dir).to receive(:mkdir).with('human/path').once
25
- expect(Dir).to receive(:mkdir).with('machine/path').once
26
- expect(model_reader).to receive(:model).with('model/path').once { entities }
27
- expect(model_generator).to receive(:generate).with(entities).once
48
+ context 'when lang is objc' do
49
+ let(:human) { double(Moblues::Generator::Objc::Human) }
50
+ let(:machine) { double(Moblues::Generator::Objc::Machine) }
51
+
52
+ before do
53
+ allow(Moblues::Generator::Objc::Human).to receive(:new) { human }
54
+ allow(Moblues::Generator::Objc::Machine).to receive(:new) { machine }
55
+ end
56
+
57
+ it_behaves_like 'generate', :objc
58
+ end
28
59
 
29
- subject.generate(model, human, machine)
60
+ context 'when lang is unknown' do
61
+ it 'raises an error' do
62
+ expect { subject.generate(model, human_dir, machine_dir, :unknown) }.to raise_exception
63
+ end
30
64
  end
31
65
  end
32
66
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ import Foundation
2
+
3
+ class Author: _Author {
4
+ }
@@ -0,0 +1,11 @@
1
+ import Foundation
2
+ import CoreData
3
+
4
+ class _Author: Person {
5
+ @NSManaged var dob: NSDate
6
+ @NSManaged var name: String
7
+
8
+ @NSManaged var books: NSOrderedSet
9
+ @NSManaged var essays: NSSet
10
+ @NSManaged var publisher: Publisher
11
+ }
@@ -0,0 +1,8 @@
1
+ import Foundation
2
+ import CoreData
3
+
4
+ class _Book: NSManagedObject {
5
+ @NSManaged var name: String
6
+
7
+ @NSManaged var editions: NSSet
8
+ }
@@ -0,0 +1,4 @@
1
+ import Foundation
2
+
3
+ class Playable: _Playable {
4
+ }
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ class Playlist: _Playlist {
4
+ /* some modifications that should not be erased */
5
+ }
@@ -0,0 +1,4 @@
1
+ import Foundation
2
+
3
+ class Track: _Track {
4
+ }
@@ -0,0 +1,4 @@
1
+ import Foundation
2
+
3
+ class User: _User {
4
+ }
@@ -0,0 +1,8 @@
1
+ import Foundation
2
+ import CoreData
3
+
4
+ class _Playable: NSManagedObject {
5
+ @NSManaged var permalink: String
6
+ @NSManaged var title: String
7
+
8
+ }
@@ -0,0 +1,8 @@
1
+ import Foundation
2
+ import CoreData
3
+
4
+ class _Playlist: Playable {
5
+
6
+ @NSManaged var tracks: NSOrderedSet
7
+ @NSManaged var user: User
8
+ }
@@ -0,0 +1,9 @@
1
+ import Foundation
2
+ import CoreData
3
+
4
+ class _Track: Playable {
5
+ @NSManaged var duration: NSNumber
6
+
7
+ @NSManaged var playlist: Playlist
8
+ @NSManaged var user: User
9
+ }
@@ -0,0 +1,10 @@
1
+ import Foundation
2
+ import CoreData
3
+
4
+ class _User: NSManagedObject {
5
+ @NSManaged var dob: NSDate
6
+ @NSManaged var name: String
7
+
8
+ @NSManaged var playlists: NSSet
9
+ @NSManaged var tracks: NSSet
10
+ }
@@ -7,6 +7,34 @@ FactoryGirl.define do
7
7
  name 'attribute'
8
8
  type :string
9
9
 
10
+ trait :string do
11
+ type :string
12
+ end
13
+
14
+ trait :number do
15
+ type :number
16
+ end
17
+
18
+ trait :decimal do
19
+ type :decimal
20
+ end
21
+
22
+ trait :date do
23
+ type :date
24
+ end
25
+
26
+ trait :data do
27
+ type :data
28
+ end
29
+
30
+ trait :id do
31
+ type :id
32
+ end
33
+
34
+ trait :unknown do
35
+ type :unknown
36
+ end
37
+
10
38
  initialize_with { new(name: name, type: type) }
11
39
  end
12
40
  end
@@ -9,6 +9,21 @@ FactoryGirl.define do
9
9
  to_many true
10
10
  ordered true
11
11
 
12
+ trait :single do
13
+ to_many false
14
+ ordered false
15
+ end
16
+
17
+ trait :to_many do
18
+ to_many true
19
+ ordered false
20
+ end
21
+
22
+ trait :to_many_ordered do
23
+ to_many true
24
+ ordered true
25
+ end
26
+
12
27
  initialize_with { new(name: name, destination_entity: destination_entity, to_many: to_many, ordered: ordered) }
13
28
  end
14
29
  end