Skip to content

Commit

Permalink
Add created_attributes_for in case factory attributes do not line up
Browse files Browse the repository at this point in the history
  • Loading branch information
jtescher committed Aug 20, 2013
1 parent 34e05ea commit c00a807
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Tested against ruby-head, ruby 2.0.0, ruby 1.9.3, jruby-19mode, jruby-head, and
(https://gemnasium.com/jtescher/factory_girl-remote_api)
[![Coverage Status](https://coveralls.io/repos/jtescher/factory_girl-remote_api/badge.png)]
(https://coveralls.io/r/jtescher/factory_girl-remote_api)
[![Gem Version](https://badge.fury.io/rb/factory_girl-remote_api.png)
](http://badge.fury.io/rb/factory_girl-remote_api)


##Installation
Expand Down
1 change: 1 addition & 0 deletions factory_girl-remote_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Gem::Specification.new do |s|
s.description = 'Simply creates an HTTP API for your FactoryGirl factories to be used by client tests.'
s.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $0 =~ /gem\z/
s.cert_chain = ['gem-public_cert.pem']
s.license = 'MIT'

s.files = Dir['{app,config,db,lib}/**/*'] + ['MIT-LICENSE', 'Rakefile', 'README.md']

Expand Down
4 changes: 4 additions & 0 deletions lib/factory_girl/remote_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,9 @@ def self.attributes_for(factory, attributes = {})
FactoryGirl::RemoteApi::Request.new.get_response_for(:attributes_for, factory, attributes)
end

def self.created_attributes_for(factory, attributes = {})
FactoryGirl::RemoteApi::Request.new.get_response_for(:create, factory, attributes)
end

end
end
7 changes: 0 additions & 7 deletions lib/factory_girl/remote_api/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ module FactoryGirl
module RemoteApi
class Engine < ::Rails::Engine
isolate_namespace FactoryGirl::RemoteApi

config.generators do |g|
g.test_framework :rspec, fixture: false
g.fixture_replacement :factory_girl, dir: 'spec/factories'
g.assets false
g.helper false
end
end
end
end
16 changes: 16 additions & 0 deletions spec/features/client_factory_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,20 @@
expect(user_attributes['first_name']).to eq('James')
expect(user_attributes[:first_name]).to eq('James')
end

scenario 'attributes for a created user model from a remote factory' do
stub_with_real_response('/user?')
created_user_attributes = FactoryGirl::RemoteApi.created_attributes_for(:user)
expect(User.count).to eq(1)
expect(created_user_attributes[:id]).to_not be_nil
end

scenario 'attributes for a created user model from a remote factory with specific attributes' do
stub_with_real_response('/user?user%5Bfirst_name%5D=James')
created_user_attributes = FactoryGirl::RemoteApi.created_attributes_for(:user, first_name: 'James')
expect(User.count).to eq(1)
expect(created_user_attributes[:id]).to_not be_nil
expect(created_user_attributes['first_name']).to eq('James')
expect(created_user_attributes[:first_name]).to eq('James')
end
end

0 comments on commit c00a807

Please sign in to comment.