fabrication 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/LICENSE +14 -0
  2. data/README.markdown +7 -1
  3. data/Rakefile +19 -0
  4. data/lib/fabrication.rb +11 -0
  5. data/lib/fabrication/config.rb +1 -1
  6. data/lib/fabrication/{cucumber.rb → cucumber/step_fabricator.rb} +2 -7
  7. data/lib/fabrication/fabricator.rb +6 -1
  8. data/lib/fabrication/support.rb +1 -1
  9. data/lib/fabrication/syntax/make.rb +26 -0
  10. data/lib/fabrication/transform.rb +26 -0
  11. data/lib/fabrication/version.rb +1 -1
  12. data/lib/rails/generators/fabrication/cucumber_steps/templates/fabrication_steps.rb +0 -2
  13. data/lib/rails/generators/fabrication/turnip_steps/templates/fabrication_steps.rb +57 -0
  14. data/lib/rails/generators/fabrication/turnip_steps/turnip_steps_generator.rb +21 -0
  15. metadata +156 -135
  16. data/spec/fabrication/attribute_spec.rb +0 -53
  17. data/spec/fabrication/config_spec.rb +0 -32
  18. data/spec/fabrication/cucumber_spec.rb +0 -116
  19. data/spec/fabrication/fabricator_spec.rb +0 -67
  20. data/spec/fabrication/generator/active_record_spec.rb +0 -83
  21. data/spec/fabrication/generator/base_spec.rb +0 -108
  22. data/spec/fabrication/schematic_spec.rb +0 -199
  23. data/spec/fabrication/sequencer_spec.rb +0 -98
  24. data/spec/fabrication/support_spec.rb +0 -54
  25. data/spec/fabrication_spec.rb +0 -329
  26. data/spec/fabricators/active_record_fabricator.rb +0 -21
  27. data/spec/fabricators/cool_object_fabricator.rb +0 -1
  28. data/spec/fabricators/mongoid_fabricator.rb +0 -36
  29. data/spec/fabricators/plain_old_ruby_object_fabricator.rb +0 -51
  30. data/spec/fabricators/sequel_fabricator.rb +0 -15
  31. data/spec/fabricators/sequencer_fabricator.rb +0 -9
  32. data/spec/spec_helper.rb +0 -12
  33. data/spec/support/active_record.rb +0 -65
  34. data/spec/support/mongoid.rb +0 -74
  35. data/spec/support/plain_old_ruby_objects.rb +0 -68
  36. data/spec/support/sequel.rb +0 -22
  37. data/spec/support/sequel_migrations/001_create_tables.rb +0 -23
@@ -1,21 +0,0 @@
1
- Fabricator(:parent_active_record_model) do
2
- collection_field(:count => 2, :fabricator => :child_active_record_model)
3
- dynamic_field { 'dynamic content' }
4
- nil_field nil
5
- number_field 5
6
- string_field 'content'
7
- end
8
-
9
- Fabricator(:child_active_record_model) do
10
- number_field 10
11
- end
12
-
13
- # ActiveRecord Objects
14
- Fabricator(:division) do
15
- name "Division Name"
16
- end
17
-
18
- Fabricator(:squadron, :from => :division)
19
-
20
- Fabricator(:company)
21
- Fabricator(:startup, :from => :company)
@@ -1 +0,0 @@
1
- Fabricator(:cool_object, :from => :object)
@@ -1,36 +0,0 @@
1
- Fabricator(:parent_mongoid_document) do
2
- collection_field(:count => 2, :fabricator => :child_mongoid_document)
3
- dynamic_field { 'dynamic content' }
4
- nil_field nil
5
- number_field 5
6
- string_field 'content'
7
- end
8
-
9
- Fabricator(:child_mongoid_document) do
10
- number_field 10
11
- end
12
-
13
- # Mongoid Documents
14
- Fabricator(:author) do
15
- name 'George Orwell'
16
- books(:count => 4) do |author, i|
17
- Fabricate.build(:book, :title => "book title #{i}", :author => author)
18
- end
19
- end
20
-
21
- Fabricator(:special_author, :from => :author) do
22
- mongoid_dynamic_field 50
23
- lazy_dynamic_field { "foo" }
24
- end
25
-
26
- Fabricator(:hemingway, :from => :author) do
27
- name 'Ernest Hemingway'
28
- end
29
-
30
- Fabricator(:book) do
31
- title "book title"
32
- end
33
-
34
- Fabricator(:publishing_house)
35
- Fabricator(:book_promoter)
36
- Fabricator(:professional_affiliation)
@@ -1,51 +0,0 @@
1
- Fabricator(:parent_ruby_object) do
2
- collection_field(:count => 2, :fabricator => :child_ruby_object)
3
- dynamic_field { 'dynamic content' }
4
- nil_field nil
5
- number_field 5
6
- string_field 'content'
7
- end
8
-
9
- Fabricator(:child_ruby_object) do
10
- number_field 10
11
- end
12
-
13
- # Plain Ruby Objects
14
- Fabricator(:awesome_object, :from => :object)
15
-
16
- Fabricator(:dog)
17
- Fabricator(:greyhound, :from => :dog) do
18
- breed "greyhound"
19
- locations(:count => 2)
20
- end
21
-
22
- Fabricator(:location) do
23
- lat 35
24
- lng 40
25
- end
26
- Fabricator(:interesting_location, :from => :location)
27
-
28
- Fabricator(:person) do
29
- first_name "John"
30
- last_name { Faker::Name.last_name }
31
- age { rand(100) }
32
- shoes(:count => 10) { |person, i| "shoe #{i}" }
33
- location
34
- end
35
-
36
- Fabricator(:child, :from => :person) do
37
- after_build { |child| child.first_name = 'Johnny' }
38
- after_build { |child| child.age = 10 }
39
- end
40
-
41
- Fabricator(:senior, :from => :child) do
42
- after_build { |senior| senior.age *= 7 }
43
- end
44
-
45
- Fabricator(:city) do
46
- on_init { init_with('Boulder', 'CO') }
47
- end
48
-
49
- Fabricator("Something::Amazing") do
50
- stuff "cool"
51
- end
@@ -1,15 +0,0 @@
1
- Fabricator(:parent_sequel_model) do
2
- dynamic_field { 'dynamic content' }
3
- nil_field nil
4
- number_field 5
5
- string_field 'content'
6
- after_create do |parent|
7
- 2.times do
8
- Fabricate(:child_sequel_model, :parent => parent)
9
- end
10
- end
11
- end
12
-
13
- Fabricator(:child_sequel_model) do
14
- number_field 10
15
- end
@@ -1,9 +0,0 @@
1
- Fabricator(:sequencer) do
2
- simple_iterator { sequence }
3
- param_iterator { sequence(:param_iterator, 9) }
4
- block_iterator { sequence(:block_iterator) { |i| "block#{i}" } }
5
- end
6
-
7
- Fabricator("Sequencer::Namespaced") do
8
- iterator { sequence(:iterator) }
9
- end
@@ -1,12 +0,0 @@
1
- require 'rspec'
2
- require 'fabrication'
3
- require 'ffaker'
4
-
5
- # Requires supporting files with custom matchers and macros, etc,
6
- # in ./support/ and its subdirectories.
7
- Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
8
-
9
- RSpec.configure do |config|
10
- config.before(:all) { TestMigration.up }
11
- config.before(:all) { clear_mongodb }
12
- end
@@ -1,65 +0,0 @@
1
- require 'active_record'
2
-
3
- dbconfig = {
4
- :adapter => 'sqlite3',
5
- :database => ':memory:'
6
- }
7
-
8
- ActiveRecord::Base.establish_connection(dbconfig)
9
- ActiveRecord::Migration.verbose = false
10
-
11
- class TestMigration < ActiveRecord::Migration
12
- def self.up
13
- create_table :child_active_record_models, :force => true do |t|
14
- t.column :parent_active_record_model_id, :integer
15
- t.column :number_field, :integer
16
- end
17
-
18
- create_table :parent_active_record_models, :force => true do |t|
19
- t.column :before_save_value, :integer
20
- t.column :dynamic_field, :string
21
- t.column :nil_field, :string
22
- t.column :number_field, :integer
23
- t.column :string_field, :string
24
- end
25
-
26
- create_table :companies, :force => true do |t|
27
- t.column :name, :string
28
- t.column :city, :string
29
- end
30
-
31
- create_table :divisions, :force => true do |t|
32
- t.column :name, :string
33
- t.references :company
34
- end
35
- end
36
-
37
- def self.down
38
- drop_table :child_active_record_models
39
- drop_table :parent_active_record_models
40
- drop_table :companies
41
- drop_table :divisions
42
- end
43
- end
44
-
45
- class ChildActiveRecordModel < ActiveRecord::Base
46
- belongs_to :parent, :class_name => 'ParentActiveRecordModel'
47
- end
48
-
49
- class ParentActiveRecordModel < ActiveRecord::Base
50
- has_many :collection_field, :class_name => 'ChildActiveRecordModel'
51
-
52
- before_save do
53
- self.before_save_value = 11
54
- end
55
- end
56
-
57
- class Company < ActiveRecord::Base
58
- has_many :divisions
59
-
60
- attr_accessor :non_field
61
- end
62
-
63
- class Division < ActiveRecord::Base
64
- belongs_to :company
65
- end
@@ -1,74 +0,0 @@
1
- require 'mongoid'
2
-
3
- Mongoid.configure do |config|
4
- config.allow_dynamic_fields = true
5
- config.master = Mongo::Connection.new.db("fabrication_test")
6
- end
7
-
8
- def clear_mongodb
9
- Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
10
- end
11
-
12
- class ChildMongoidDocument
13
- include Mongoid::Document
14
-
15
- field :number_field
16
-
17
- referenced_in :parent, :class_name => 'ParentMongoidDocument'
18
- end
19
-
20
- class ParentMongoidDocument
21
- include Mongoid::Document
22
-
23
- field :before_save_value
24
- field :dynamic_field
25
- field :nil_field
26
- field :number_field
27
- field :string_field
28
-
29
- references_many :collection_field, :class_name => 'ChildMongoidDocument', :inverse_of => :parent
30
-
31
- before_save do
32
- self.before_save_value = 11
33
- end
34
- end
35
-
36
- class Author
37
- include Mongoid::Document
38
-
39
- embeds_many :books
40
-
41
- field :name
42
- field :handle
43
- end
44
-
45
- class Book
46
- include Mongoid::Document
47
-
48
- field :title
49
-
50
- embedded_in :author, :inverse_of => :books
51
- end
52
-
53
- class PublishingHouse
54
- include Mongoid::Document
55
-
56
- referenced_in :professional_affiliation
57
- embeds_many :book_promoters
58
-
59
- field :name
60
- end
61
-
62
- class BookPromoter
63
- include Mongoid::Document
64
-
65
- embedded_in :publishing_house
66
-
67
- field :name
68
- end
69
-
70
- class ProfessionalAffiliation
71
- include Mongoid::Document
72
-
73
- references_many :publishing_houses
74
- end
@@ -1,68 +0,0 @@
1
- require 'ostruct'
2
-
3
- class ParentRubyObject
4
- attr_accessor \
5
- :before_save_value,
6
- :collection_field,
7
- :dynamic_field,
8
- :nil_field,
9
- :number_field,
10
- :string_field
11
-
12
- def initialize
13
- self.before_save_value = 11
14
- end
15
-
16
- def persisted?; true end
17
- end
18
-
19
- class ChildRubyObject
20
- attr_accessor \
21
- :parent,
22
- :number_field
23
-
24
- def persisted?; true end
25
- end
26
-
27
- class Dog
28
- attr_accessor :name, :breed, :locations
29
- end
30
-
31
- class Location
32
- attr_accessor :lat, :lng
33
- end
34
-
35
- class Person
36
- attr_accessor :age, :first_name, :last_name, :shoes, :location
37
- end
38
-
39
- class City
40
- attr_accessor :city, :state
41
-
42
- def initialize(city, state)
43
- self.city = city
44
- self.state = state
45
- end
46
- end
47
-
48
- class Address
49
- attr_accessor :city, :state
50
- end
51
-
52
- class Contact
53
- attr_accessor :name, :address
54
- end
55
-
56
- module Something
57
- class Amazing
58
- attr_accessor :stuff
59
- end
60
- end
61
-
62
- class Sequencer
63
- attr_accessor :simple_iterator, :param_iterator, :block_iterator
64
-
65
- class Namespaced
66
- attr_accessor :iterator
67
- end
68
- end
@@ -1,22 +0,0 @@
1
- require 'sequel'
2
-
3
- DB = Sequel.sqlite # in memory
4
- Sequel.extension :migration
5
- Sequel::Migrator.run(DB, 'spec/support/sequel_migrations', :current => 0)
6
-
7
- class ChildSequelModel < Sequel::Model
8
- many_to_one :parent, :class => :ParentSequelModel, :key => :parent_sequel_model_id
9
-
10
- def persisted?; !new? end
11
- end
12
-
13
- class ParentSequelModel < Sequel::Model
14
- one_to_many :collection_field, :class => :ChildSequelModel, :key => :parent_sequel_model_id
15
-
16
- def persisted?; !new? end
17
-
18
- def before_save
19
- self.before_save_value = 11
20
- super
21
- end
22
- end
@@ -1,23 +0,0 @@
1
- Sequel.migration do
2
- up do
3
- create_table :child_sequel_models do
4
- primary_key :id
5
- Integer :parent_sequel_model_id
6
- Integer :number_field
7
- end
8
-
9
- create_table :parent_sequel_models do
10
- primary_key :id
11
- Integer :before_save_value
12
- String :dynamic_field
13
- String :nil_field
14
- Integer :number_field
15
- String :string_field
16
- end
17
- end
18
-
19
- down do
20
- drop_table :child_sequel_models
21
- drop_table :parent_sequel_models
22
- end
23
- end