factory_girl-remote_api 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +168 -0
- data/Rakefile +58 -0
- data/app/assets/javascripts/factory_girl-remote_api/application.js +13 -0
- data/app/assets/stylesheets/factory_girl-remote_api/application.css +13 -0
- data/app/controllers/factory_girl/remote_api/application_controller.rb +6 -0
- data/app/controllers/factory_girl/remote_api/factories_controller.rb +24 -0
- data/app/helpers/factory_girl/remote_api/application_helper.rb +4 -0
- data/app/views/layouts/factory_girl/remote_api/application.html.erb +14 -0
- data/config/routes.rb +4 -0
- data/lib/factory_girl/remote_api/configuration.rb +21 -0
- data/lib/factory_girl/remote_api/engine.rb +14 -0
- data/lib/factory_girl/remote_api/remote_factory.rb +31 -0
- data/lib/factory_girl/remote_api/request.rb +40 -0
- data/lib/factory_girl/remote_api/version.rb +5 -0
- data/lib/factory_girl/remote_api.rb +35 -0
- data/spec/dummy_31/Rakefile +7 -0
- data/spec/dummy_31/app/assets/javascripts/application.js +9 -0
- data/spec/dummy_31/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy_31/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_31/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_31/app/models/user.rb +3 -0
- data/spec/dummy_31/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_31/config/application.rb +45 -0
- data/spec/dummy_31/config/boot.rb +10 -0
- data/spec/dummy_31/config/database.yml +25 -0
- data/spec/dummy_31/config/environment.rb +5 -0
- data/spec/dummy_31/config/environments/development.rb +30 -0
- data/spec/dummy_31/config/environments/production.rb +60 -0
- data/spec/dummy_31/config/environments/test.rb +39 -0
- data/spec/dummy_31/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_31/config/initializers/inflections.rb +10 -0
- data/spec/dummy_31/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_31/config/initializers/secret_token.rb +7 -0
- data/spec/dummy_31/config/initializers/session_store.rb +8 -0
- data/spec/dummy_31/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_31/config/locales/en.yml +5 -0
- data/spec/dummy_31/config/routes.rb +3 -0
- data/spec/dummy_31/config.ru +4 -0
- data/spec/dummy_31/db/development.sqlite3 +0 -0
- data/spec/dummy_31/db/migrate/20130607202020_create_users.rb +10 -0
- data/spec/dummy_31/db/schema.rb +23 -0
- data/spec/dummy_31/db/test.sqlite3 +0 -0
- data/spec/dummy_31/log/test.log +130 -0
- data/spec/dummy_31/public/404.html +26 -0
- data/spec/dummy_31/public/422.html +26 -0
- data/spec/dummy_31/public/500.html +26 -0
- data/spec/dummy_31/public/favicon.ico +0 -0
- data/spec/dummy_31/script/rails +6 -0
- data/spec/dummy_31/spec/factories/users.rb +13 -0
- data/spec/dummy_32/README.rdoc +261 -0
- data/spec/dummy_32/Rakefile +7 -0
- data/spec/dummy_32/app/assets/javascripts/application.js +15 -0
- data/spec/dummy_32/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy_32/app/controllers/application_controller.rb +3 -0
- data/spec/dummy_32/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_32/app/models/user.rb +3 -0
- data/spec/dummy_32/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_32/config/application.rb +65 -0
- data/spec/dummy_32/config/boot.rb +10 -0
- data/spec/dummy_32/config/database.yml +25 -0
- data/spec/dummy_32/config/environment.rb +5 -0
- data/spec/dummy_32/config/environments/development.rb +37 -0
- data/spec/dummy_32/config/environments/production.rb +67 -0
- data/spec/dummy_32/config/environments/test.rb +37 -0
- data/spec/dummy_32/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_32/config/initializers/inflections.rb +15 -0
- data/spec/dummy_32/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_32/config/initializers/secret_token.rb +7 -0
- data/spec/dummy_32/config/initializers/session_store.rb +8 -0
- data/spec/dummy_32/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_32/config/locales/en.yml +5 -0
- data/spec/dummy_32/config/routes.rb +3 -0
- data/spec/dummy_32/config.ru +4 -0
- data/spec/dummy_32/db/development.sqlite3 +0 -0
- data/spec/dummy_32/db/migrate/20130607202020_create_users.rb +10 -0
- data/spec/dummy_32/db/schema.rb +23 -0
- data/spec/dummy_32/db/test.sqlite3 +0 -0
- data/spec/dummy_32/log/test.log +1520 -0
- data/spec/dummy_32/public/404.html +26 -0
- data/spec/dummy_32/public/422.html +26 -0
- data/spec/dummy_32/public/500.html +25 -0
- data/spec/dummy_32/public/favicon.ico +0 -0
- data/spec/dummy_32/script/rails +6 -0
- data/spec/dummy_32/spec/factories/users.rb +13 -0
- data/spec/dummy_40/README.rdoc +28 -0
- data/spec/dummy_40/Rakefile +6 -0
- data/spec/dummy_40/app/assets/javascripts/application.js +13 -0
- data/spec/dummy_40/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy_40/app/controllers/application_controller.rb +5 -0
- data/spec/dummy_40/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_40/app/models/user.rb +2 -0
- data/spec/dummy_40/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy_40/bin/bundle +3 -0
- data/spec/dummy_40/bin/rails +4 -0
- data/spec/dummy_40/bin/rake +4 -0
- data/spec/dummy_40/config/application.rb +23 -0
- data/spec/dummy_40/config/boot.rb +5 -0
- data/spec/dummy_40/config/database.yml +25 -0
- data/spec/dummy_40/config/environment.rb +5 -0
- data/spec/dummy_40/config/environments/development.rb +29 -0
- data/spec/dummy_40/config/environments/production.rb +80 -0
- data/spec/dummy_40/config/environments/test.rb +36 -0
- data/spec/dummy_40/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_40/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy_40/config/initializers/inflections.rb +16 -0
- data/spec/dummy_40/config/initializers/mime_types.rb +5 -0
- data/spec/dummy_40/config/initializers/secret_token.rb +12 -0
- data/spec/dummy_40/config/initializers/session_store.rb +3 -0
- data/spec/dummy_40/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_40/config/locales/en.yml +23 -0
- data/spec/dummy_40/config/routes.rb +4 -0
- data/spec/dummy_40/config.ru +4 -0
- data/spec/dummy_40/db/migrate/20130607202020_create_users.rb +10 -0
- data/spec/dummy_40/db/schema.rb +23 -0
- data/spec/dummy_40/db/test.sqlite3 +0 -0
- data/spec/dummy_40/log/test.log +175 -0
- data/spec/dummy_40/public/404.html +58 -0
- data/spec/dummy_40/public/422.html +58 -0
- data/spec/dummy_40/public/500.html +57 -0
- data/spec/dummy_40/public/favicon.ico +0 -0
- data/spec/dummy_40/spec/factories/users.rb +13 -0
- data/spec/factory_girl/remote_api/configuration_spec.rb +24 -0
- data/spec/factory_girl/remote_api/request_spec.rb +34 -0
- data/spec/factory_girl/remote_api_spec.rb +21 -0
- data/spec/features/client_factory_requests_spec.rb +59 -0
- data/spec/features/server_factory_requests_spec.rb +50 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/database_cleaner.rb +11 -0
- data/spec/support/require_dummy_factories.rb +2 -0
- data/spec/support/stub_with_real_response.rb +12 -0
- data.tar.gz.sig +0 -0
- metadata +485 -0
- metadata.gz.sig +0 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Julian Tescher
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# FactoryGirl::RemoteApi
|
2
|
+
|
3
|
+
Simply creates an HTTP API for your FactoryGirl factories to be used by client tests.
|
4
|
+
|
5
|
+
Tested against ruby-head, ruby 2.0.0, ruby 1.9.3, jruby-19mode, jruby-head, and rbx-19mode
|
6
|
+
|
7
|
+
[![Build Status](https://travis-ci.org/jtescher/factory_girl-remote_api.png?branch=master)]
|
8
|
+
(https://travis-ci.org/jtescher/factory_girl-remote_api)
|
9
|
+
[![Code Climate](https://codeclimate.com/github/jtescher/factory_girl-remote_api.png)]
|
10
|
+
(https://codeclimate.com/github/jtescher/factory_girl-remote_api)
|
11
|
+
[![Dependency Status](https://gemnasium.com/jtescher/factory_girl-remote_api.png)]
|
12
|
+
(https://gemnasium.com/jtescher/factory_girl-remote_api)
|
13
|
+
[![Coverage Status](https://coveralls.io/repos/jtescher/factory_girl-remote_api/badge.png)]
|
14
|
+
(https://coveralls.io/r/jtescher/factory_girl-remote_api)
|
15
|
+
|
16
|
+
|
17
|
+
##Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'factory_girl-remote_api', '~> 0.2.1'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
```bash
|
27
|
+
$ bundle
|
28
|
+
```
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
```bash
|
32
|
+
$ gem install factory_girl-remote_api
|
33
|
+
```
|
34
|
+
|
35
|
+
Then mount as an engine in your config/routes.rb file.
|
36
|
+
```ruby
|
37
|
+
Rails.application.routes.draw do
|
38
|
+
...
|
39
|
+
mount FactoryGirl::RemoteApi::Engine => '/factories' if Rails.env.test?
|
40
|
+
...
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
First install [FactoryGirl](https://github.com/thoughtbot/factory_girl) and create some
|
48
|
+
[factories](https://github.com/thoughtbot/factory_girl/wiki/Usage).
|
49
|
+
|
50
|
+
To use with a client application, start rails in the `test` environment
|
51
|
+
(or whichever environment has the engine mounted).
|
52
|
+
```bash
|
53
|
+
$ rails server -e test
|
54
|
+
```
|
55
|
+
|
56
|
+
Then any FactoryGirl factories you have defined will be available at `/mount_path/:factory_name`
|
57
|
+
|
58
|
+
### Example
|
59
|
+
|
60
|
+
A user factory in spec/factories/users.rb:
|
61
|
+
```ruby
|
62
|
+
FactoryGirl.define do
|
63
|
+
factory :user do
|
64
|
+
first_name 'John'
|
65
|
+
last_name 'Doe'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
And FactoryGirl::RemoteApi mounted at /factories:
|
71
|
+
```ruby
|
72
|
+
Rails.application.routes.draw do
|
73
|
+
mount FactoryGirl::RemoteApi::Engine => '/factories' if Rails.env.test?
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
Will make the created user available via any client:
|
78
|
+
```bash
|
79
|
+
$ curl http://localhost:3000/factories/user?user[first_name]=John&user[last_name]=Doe
|
80
|
+
{
|
81
|
+
"created_at": "2013-06-07T23:02:32Z",
|
82
|
+
"first_name": "John",
|
83
|
+
"id": 1,
|
84
|
+
"last_name": "Doe",
|
85
|
+
"updated_at": "2013-06-07T23:02:32Z"
|
86
|
+
}
|
87
|
+
```
|
88
|
+
|
89
|
+
And attributes for the user without creating it:
|
90
|
+
```bash
|
91
|
+
$ curl http://localhost:3000/factories/attributes_for/user?user[first_name]=John
|
92
|
+
{
|
93
|
+
"first_name": "John",
|
94
|
+
"last_name": "FactoryDefaultLastName",
|
95
|
+
}
|
96
|
+
```
|
97
|
+
|
98
|
+
## Usage (As Client)
|
99
|
+
|
100
|
+
FactoryGirl::RemoteApi can also be used between rails servers by the client rails app.
|
101
|
+
First install the gem (You don't have to mount the engine in routes.rb)
|
102
|
+
|
103
|
+
Then configure the server URL (if different than localhost:3000/factories) in
|
104
|
+
`spec/support/factory_girl-remote_api.rb`
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
FactoryGirl::RemoteApi.configure do |config|
|
108
|
+
config.server_url = 'http://localhost:3001' # Default: http://localhost:3000
|
109
|
+
config.server_mount_path = '/remote_models' # Default: /factories
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
Then you can create records on the server rails app during tests by includeing the following in your test files:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
it 'Does something with a model that is persisted on the server' do
|
117
|
+
user = FactoryGirl::RemoteApi.create(:user)
|
118
|
+
user.id #=> 1
|
119
|
+
user.first_name #=> "Tom"
|
120
|
+
user.last_name #=> "Smith"
|
121
|
+
...
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
And you can build records on the client rails app during tests by includeing the following in your test files:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
it 'Does something with a model that is persisted on the server' do
|
129
|
+
user = FactoryGirl::RemoteApi.build(:user)
|
130
|
+
user.id #=> nil
|
131
|
+
user.first_name #=> "Tom"
|
132
|
+
user.last_name #=> "Smith"
|
133
|
+
...
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
And you can get attributes for models defined in factories on the server as well:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
it 'Does something with attributes of a model that are not persisted on the server' do
|
141
|
+
user_attributes = FactoryGirl::RemoteApi.attributes_for(:user, first_name: 'John')
|
142
|
+
user_attributes[:id] #=> nil
|
143
|
+
user_attributes[:first_name] #=> "John"
|
144
|
+
user_attributes[:last_name] #=> "Smith"
|
145
|
+
...
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
It is also possible to create or get attributes of a child factory:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
it 'Does something with attributes of a child factory' do
|
153
|
+
user_attributes = FactoryGirl::RemoteApi.attributes_for(:expired_user, parent_factory: 'user')
|
154
|
+
user_attributes[:id] #=> nil
|
155
|
+
user_attributes[:first_name] #=> "John"
|
156
|
+
user_attributes[:last_name] #=> "Smith"
|
157
|
+
...
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
## Contributing
|
163
|
+
|
164
|
+
1. Fork it
|
165
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
166
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
167
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
168
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'appraisal'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler/setup'
|
7
|
+
rescue LoadError
|
8
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
9
|
+
end
|
10
|
+
begin
|
11
|
+
require 'rdoc/task'
|
12
|
+
rescue LoadError
|
13
|
+
require 'rdoc/rdoc'
|
14
|
+
require 'rake/rdoctask'
|
15
|
+
RDoc::Task = Rake::RDocTask
|
16
|
+
end
|
17
|
+
|
18
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
19
|
+
rdoc.rdoc_dir = 'rdoc'
|
20
|
+
rdoc.title = 'FactoryGirl::RemoteApi'
|
21
|
+
rdoc.options << '--line-numbers'
|
22
|
+
rdoc.rdoc_files.include('README.rdoc')
|
23
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rspec/core'
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(spec: %w[app:db:migrate app:db:test:prepare])
|
30
|
+
rescue LoadError
|
31
|
+
desc 'spec rake task not available (rspec not installed)'
|
32
|
+
task :spec do
|
33
|
+
abort 'Spec rake task is not available. Be sure to install rspec as gem.'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Find the right dummy Rakefile to load. If in appraisal, use that version of dummy Rails, else default to 3.2.
|
38
|
+
rails_minor_version = if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
|
39
|
+
ENV['BUNDLE_GEMFILE'].split('/').last.scan(/(\d).(\d)/).join
|
40
|
+
else
|
41
|
+
'32'
|
42
|
+
end
|
43
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy_#{rails_minor_version}/Rakefile", __FILE__)
|
44
|
+
|
45
|
+
# Ensure the dummy app is in the test environment
|
46
|
+
ENV['RAILS_ENV'] ||= 'test'
|
47
|
+
|
48
|
+
# Stop Rails from resetting the BUNDLE_GEMFILE env variable on load.
|
49
|
+
old_bundle_gemfile = ENV['BUNDLE_GEMFILE']
|
50
|
+
load 'rails/tasks/engine.rake'
|
51
|
+
ENV['BUNDLE_GEMFILE'] = old_bundle_gemfile
|
52
|
+
|
53
|
+
# Load all tasks
|
54
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
55
|
+
|
56
|
+
Bundler::GemHelper.install_tasks
|
57
|
+
|
58
|
+
task default: :spec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// the compiled file.
|
9
|
+
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FactoryGirl
|
2
|
+
module RemoteApi
|
3
|
+
class FactoriesController < FactoryGirl::RemoteApi::ApplicationController
|
4
|
+
respond_to :json
|
5
|
+
|
6
|
+
def create
|
7
|
+
@model = FactoryGirl.create(params[:factory], factory_attributes)
|
8
|
+
respond_with @model
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
@model = FactoryGirl.attributes_for(params[:factory], factory_attributes)
|
13
|
+
respond_with @model
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def factory_attributes
|
19
|
+
params[params[:factory]].try(:except, :parent_factory)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>FactoryGirl::RemoteApi</title>
|
5
|
+
<%= stylesheet_link_tag "factory_girl/remote_api/application", :media => "all" %>
|
6
|
+
<%= javascript_include_tag "factory_girl/remote_api/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module FactoryGirl
|
2
|
+
module RemoteApi
|
3
|
+
class Configuration
|
4
|
+
attr_reader :server_url, :server_mount_path
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@server_url = 'http://localhost:3000'
|
8
|
+
@server_mount_path = '/factories'
|
9
|
+
end
|
10
|
+
|
11
|
+
def server_url=(server_url)
|
12
|
+
@server_url = server_url.gsub(/\/$/, '')
|
13
|
+
end
|
14
|
+
|
15
|
+
def server_mount_path=(server_mount_path)
|
16
|
+
@server_mount_path = "/#{server_mount_path}".squeeze('/').gsub(/\/+\Z/, '')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module FactoryGirl
|
2
|
+
module RemoteApi
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace FactoryGirl::RemoteApi
|
5
|
+
|
6
|
+
config.generators do |g|
|
7
|
+
g.test_framework :rspec, fixture: false
|
8
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
9
|
+
g.assets false
|
10
|
+
g.helper false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'factory_girl/remote_api/request'
|
2
|
+
|
3
|
+
module FactoryGirl
|
4
|
+
module RemoteApi
|
5
|
+
class RemoteFactory
|
6
|
+
|
7
|
+
def self.model_from(factory_method, factory, attributes)
|
8
|
+
final_attributes = FactoryGirl::RemoteApi::Request.new.get_response_for(factory_method, factory, attributes)
|
9
|
+
new.instantiate_model(final_attributes, factory, attributes)
|
10
|
+
end
|
11
|
+
|
12
|
+
def instantiate_model(final_attributes, factory, attributes)
|
13
|
+
model_instance = model_class(factory, attributes).new
|
14
|
+
apply_attributes_to_instance(final_attributes, model_instance)
|
15
|
+
model_instance
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def model_class(factory, attributes)
|
21
|
+
class_name = attributes[:parent_factory] || factory.to_s
|
22
|
+
class_name.camelize.constantize
|
23
|
+
end
|
24
|
+
|
25
|
+
def apply_attributes_to_instance(attributes, model_instance)
|
26
|
+
attributes.each { |attr_name, attr_value| model_instance.public_send("#{attr_name}=", attr_value) }
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module FactoryGirl
|
5
|
+
module RemoteApi
|
6
|
+
class Request
|
7
|
+
|
8
|
+
def get_response_for(factory_method, factory, attributes)
|
9
|
+
uri = uri_for(factory_method, factory)
|
10
|
+
uri.query = attributes_as_query(factory, attributes)
|
11
|
+
parsed_response(Net::HTTP.get_response(uri).body, attributes[:parent_factory] || factory.to_s)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def uri_for(factory_method, factory)
|
17
|
+
factories_path = "#{configuration.server_url}#{configuration.server_mount_path}"
|
18
|
+
factories_path << "/#{factory_method}" if factory_method != :create
|
19
|
+
factories_path << "/#{factory}"
|
20
|
+
URI(factories_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def configuration
|
24
|
+
FactoryGirl::RemoteApi.configuration
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes_as_query(factory, attributes)
|
28
|
+
attributes = { factory.to_sym => attributes } if attributes != {}
|
29
|
+
attributes.to_query
|
30
|
+
end
|
31
|
+
|
32
|
+
def parsed_response(response_body, json_root)
|
33
|
+
response_json = JSON.parse(response_body)
|
34
|
+
attributes = response_json.key?(json_root) ? response_json[json_root] : response_json
|
35
|
+
attributes.with_indifferent_access
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'factory_girl'
|
2
|
+
require 'factory_girl_rails'
|
3
|
+
require 'factory_girl/remote_api/engine'
|
4
|
+
require 'factory_girl/remote_api/configuration'
|
5
|
+
require 'factory_girl/remote_api/remote_factory'
|
6
|
+
|
7
|
+
module FactoryGirl
|
8
|
+
module RemoteApi
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield configuration if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configuration
|
15
|
+
@configuration ||= FactoryGirl::RemoteApi::Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.reset_configuration
|
19
|
+
@configuration = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.create(factory, attributes = {})
|
23
|
+
FactoryGirl::RemoteApi::RemoteFactory.model_from(:create, factory, attributes)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.build(factory, attributes = {})
|
27
|
+
FactoryGirl::RemoteApi::RemoteFactory.model_from(:build, factory, attributes)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.attributes_for(factory, attributes = {})
|
31
|
+
FactoryGirl::RemoteApi::Request.new.get_response_for(:attributes_for, factory, attributes)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require
|
6
|
+
require "factory_girl/remote_api"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
15
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
16
|
+
|
17
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
18
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
19
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
20
|
+
|
21
|
+
# Activate observers that should always be running.
|
22
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
23
|
+
|
24
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
25
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
26
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
27
|
+
|
28
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
29
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
30
|
+
# config.i18n.default_locale = :de
|
31
|
+
|
32
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
33
|
+
config.encoding = "utf-8"
|
34
|
+
|
35
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
36
|
+
config.filter_parameters += [:password]
|
37
|
+
|
38
|
+
# Enable the asset pipeline
|
39
|
+
config.assets.enabled = true
|
40
|
+
|
41
|
+
# Version of your assets, change this if you want to expire all your assets
|
42
|
+
config.assets.version = '1.0'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the web server when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_controller.perform_caching = false
|
15
|
+
|
16
|
+
# Don't care if the mailer can't send
|
17
|
+
config.action_mailer.raise_delivery_errors = false
|
18
|
+
|
19
|
+
# Print deprecation notices to the Rails logger
|
20
|
+
config.active_support.deprecation = :log
|
21
|
+
|
22
|
+
# Only use best-standards-support built into browsers
|
23
|
+
config.action_dispatch.best_standards_support = :builtin
|
24
|
+
|
25
|
+
# Do not compress assets
|
26
|
+
config.assets.compress = false
|
27
|
+
|
28
|
+
# Expands the lines which load the assets
|
29
|
+
config.assets.debug = true
|
30
|
+
end
|