fg-quickgenerate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fg-quickgenerate.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Hugo Roque
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # fg-quickgenerate (FactoryGirl addon)
2
+
3
+ Hello fellas! This gem was create to made easy way of creating quick sequences in FactoryGirl.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'fg-quickgenerate'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install fg-quickgenerate
18
+
19
+ ## Usage
20
+
21
+ First of all, require fg-quickgenerate below FactoryGirl require, like that:
22
+ require 'factory_girl'
23
+ require 'fg-quickgenerate'
24
+
25
+ After require you will be able to create simple sequentials like:
26
+
27
+ FactoryGirl.define do
28
+ factory :user do
29
+ name { sequential("myname") }
30
+ email { sequential("myemail#N@email.com") }
31
+ end
32
+ end
33
+
34
+
35
+ Doing this, your tests will look like that:
36
+
37
+ u1 = build(:user)
38
+ u1.name # myname1
39
+ u1.email # myemail1@email.com
40
+
41
+ u2 = build(:user)
42
+ u2.name # myname2
43
+ u2.email # myemail2@email.com
44
+
45
+
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/fg-quickgenerate/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Hugo Roque (a.k.a hugolnx)"]
6
+ gem.email = ["hugolnx@gmail.com"]
7
+ gem.description = %q{plugin for FactoryGirl: Easy way to quick generate samples}
8
+ gem.summary = %q{plugin for FactoryGirl: Easy way to quick generate samples}
9
+ gem.homepage = "http://github.com/hugolnx/fg-quickgenerate"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "fg-quickgenerate"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Fg::Quickgenerate::VERSION
17
+
18
+ gem.add_runtime_dependency(%q<factory_girl>, ["~> 4.x.x"])
19
+
20
+ gem.add_development_dependency 'rspec', '~> 2.x.x'
21
+ end
@@ -0,0 +1,39 @@
1
+ require "fg-quickgenerate/version"
2
+
3
+ module Fg
4
+ module Quickgenerate
5
+ # Your code goes here...
6
+ # Ohhh, I don't want to refactor :P
7
+ end
8
+ end
9
+
10
+ module FactoryGirl
11
+ module Syntax::Methods
12
+ def sequential(string)
13
+ name = :"___autogenerated_#{string}___"
14
+
15
+ begin
16
+ sequence = FactoryGirl.sequence_by_name(name)
17
+ rescue Exception => e
18
+ sequence = FactoryGirl.create_simple_sequence(name, string)
19
+ end
20
+
21
+ sequence.next
22
+ end
23
+ end
24
+
25
+ def self.create_simple_sequence(name, string)
26
+ sequence = Sequence.simple(name, string)
27
+ FactoryGirl.register_sequence(sequence)
28
+ end
29
+
30
+ class Sequence
31
+ SIMPLE_REPLACEMENT = "#N"
32
+
33
+ def self.simple(name, string)
34
+ string += SIMPLE_REPLACEMENT unless string.include? SIMPLE_REPLACEMENT
35
+ Sequence.new(name){|n| string.gsub(SIMPLE_REPLACEMENT, n.to_s)}
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,5 @@
1
+ module Fg
2
+ module Quickgenerate
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe "#sequential" do
4
+ include FactoryGirl::Syntax::Methods
5
+
6
+ context 'passing string with #N' do
7
+ it "generates string increasing #N sequentialy" do
8
+ sequential("nickname#N@email.com").should == "nickname1@email.com"
9
+ sequential("nickname#N@email.com").should == "nickname2@email.com"
10
+ sequential("nickname#N@email.com").should == "nickname3@email.com"
11
+ end
12
+ end
13
+
14
+ context 'passing string without #N' do
15
+ it "puts #N in string end" do
16
+ sequential("nickname").should == "nickname1"
17
+ sequential("nickname").should == "nickname2"
18
+ sequential("nickname").should == "nickname3"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ require 'factory_girl'
2
+
3
+ require 'fg-quickgenerate'
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fg-quickgenerate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Hugo Roque (a.k.a hugolnx)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: factory_girl
16
+ requirement: &73907450 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 4.x.x
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *73907450
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &73907150 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.x.x
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *73907150
36
+ description: ! 'plugin for FactoryGirl: Easy way to quick generate samples'
37
+ email:
38
+ - hugolnx@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - fg-quickgenerate.gemspec
49
+ - lib/fg-quickgenerate.rb
50
+ - lib/fg-quickgenerate/version.rb
51
+ - spec/acceptance_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: http://github.com/hugolnx/fg-quickgenerate
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.15
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: ! 'plugin for FactoryGirl: Easy way to quick generate samples'
77
+ test_files:
78
+ - spec/acceptance_spec.rb
79
+ - spec/spec_helper.rb
80
+ has_rdoc: