moblues 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/lib/moblues/cli.rb +3 -4
- data/lib/moblues/generator/base/model.rb +24 -0
- data/lib/moblues/generator/base/type.rb +63 -0
- data/lib/moblues/generator/objc/base.rb +67 -0
- data/lib/moblues/generator/objc/human.rb +27 -0
- data/lib/moblues/generator/{human_header.h.erb → objc/human_header.h.erb} +0 -0
- data/lib/moblues/generator/{human_implementation.m.erb → objc/human_implementation.m.erb} +0 -0
- data/lib/moblues/generator/objc/machine.rb +31 -0
- data/lib/moblues/generator/{machine_header.h.erb → objc/machine_header.h.erb} +2 -2
- data/lib/moblues/generator/{machine_implementation.m.erb → objc/machine_implementation.m.erb} +0 -0
- data/lib/moblues/generator/objc/type.rb +24 -0
- data/lib/moblues/generator/swift/base.rb +39 -0
- data/lib/moblues/generator/swift/human.rb +18 -0
- data/lib/moblues/generator/swift/human.swift.erb +4 -0
- data/lib/moblues/generator/swift/machine.rb +18 -0
- data/lib/moblues/generator/swift/machine.swift.erb +12 -0
- data/lib/moblues/generator.rb +9 -4
- data/lib/moblues/reader/type.rb +3 -37
- data/lib/moblues/version.rb +1 -1
- data/lib/moblues.rb +20 -4
- data/spec/features/moblues_spec.rb +35 -16
- data/spec/lib/moblues/cli_spec.rb +12 -2
- data/spec/lib/moblues/generator/base/model_spec.rb +27 -0
- data/spec/lib/moblues/generator/base/type_spec.rb +46 -0
- data/spec/lib/moblues/generator/objc/human_spec.rb +54 -0
- data/spec/lib/moblues/generator/{machine_spec.rb → objc/machine_spec.rb} +9 -8
- data/spec/lib/moblues/generator/objc/type_spec.rb +23 -0
- data/spec/lib/moblues/generator/swift/human_spec.rb +34 -0
- data/spec/lib/moblues/generator/swift/machine_spec.rb +57 -0
- data/spec/lib/moblues/reader/type_spec.rb +3 -54
- data/spec/moblues_spec.rb +46 -12
- data/spec/resources/expected/{Author.h → objc/Author.h} +0 -0
- data/spec/resources/expected/{Author.m → objc/Author.m} +0 -0
- data/spec/resources/expected/{_Author.h → objc/_Author.h} +0 -0
- data/spec/resources/expected/{_Author.m → objc/_Author.m} +0 -0
- data/spec/resources/expected/{_Book.h → objc/_Book.h} +0 -0
- data/spec/resources/expected/{_Book.m → objc/_Book.m} +0 -0
- data/spec/resources/expected/{_Person.h → objc/_Person.h} +0 -0
- data/spec/resources/expected/{_Person.m → objc/_Person.m} +0 -0
- data/spec/resources/expected/{_Team.h → objc/_Team.h} +0 -0
- data/spec/resources/expected/{_Team.m → objc/_Team.m} +0 -0
- data/spec/resources/expected/{human → objc/human}/Playable.h +0 -0
- data/spec/resources/expected/{human → objc/human}/Playable.m +0 -0
- data/spec/resources/expected/{human → objc/human}/Playlist.h +0 -0
- data/spec/resources/expected/{human → objc/human}/Playlist.m +0 -0
- data/spec/resources/expected/{human → objc/human}/Track.h +0 -0
- data/spec/resources/expected/{human → objc/human}/Track.m +0 -0
- data/spec/resources/expected/{human → objc/human}/User.h +0 -0
- data/spec/resources/expected/{human → objc/human}/User.m +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_Playable.h +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_Playable.m +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_Playlist.h +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_Playlist.m +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_Track.h +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_Track.m +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_User.h +0 -0
- data/spec/resources/expected/{machine → objc/machine}/_User.m +0 -0
- data/spec/resources/expected/swift/Author.swift +4 -0
- data/spec/resources/expected/swift/_Author.swift +11 -0
- data/spec/resources/expected/swift/_Book.swift +8 -0
- data/spec/resources/expected/swift/human/Playable.swift +4 -0
- data/spec/resources/expected/swift/human/Playlist.swift +5 -0
- data/spec/resources/expected/swift/human/Track.swift +4 -0
- data/spec/resources/expected/swift/human/User.swift +4 -0
- data/spec/resources/expected/swift/machine/_Playable.swift +8 -0
- data/spec/resources/expected/swift/machine/_Playlist.swift +8 -0
- data/spec/resources/expected/swift/machine/_Track.swift +9 -0
- data/spec/resources/expected/swift/machine/_User.swift +10 -0
- data/spec/resources/factories/data_model/attribute_factory.rb +28 -0
- data/spec/resources/factories/data_model/relationship_factory.rb +15 -0
- data/spec/resources/fixtures.rb +10 -10
- data/spec/resources/tmp/{human → objc/human}/Playlist.h +0 -0
- data/spec/resources/tmp/{human → objc/human}/Playlist.m +0 -0
- data/spec/resources/tmp/swift/.gitkeep +0 -0
- data/spec/resources/tmp/swift/human/Playlist.swift +5 -0
- metadata +113 -76
- data/lib/moblues/generator/base.rb +0 -65
- data/lib/moblues/generator/human.rb +0 -25
- data/lib/moblues/generator/machine.rb +0 -36
- data/lib/moblues/generator/model.rb +0 -23
- data/spec/lib/moblues/generator/human_spec.rb +0 -74
- data/spec/lib/moblues/generator/model_spec.rb +0 -27
- data/spec/resources/tmp/_Team.h +0 -18
- 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
|
-
|
5
|
+
describe Moblues::Generator::Objc::Machine do
|
6
|
+
let(:output_dir) { Fixtures.generated_dir(:objc) }
|
7
7
|
|
8
8
|
after do
|
9
|
-
|
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(:
|
12
|
-
let(:
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -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
|