fixjour-2 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development, :test do
4
+ gem "rails", "~> 3.0.0"
5
+ gem "rspec", "~> 2.3.0"
6
+ gem "rspec-rails", "~> 2.3.0"
7
+ gem "sqlite3"
8
+ gem "acts_as_fu"
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ acts_as_fu (0.0.7.2)
32
+ activerecord
33
+ sqlite3-ruby
34
+ arel (2.0.7)
35
+ builder (2.1.2)
36
+ diff-lcs (1.1.2)
37
+ erubis (2.6.6)
38
+ abstract (>= 1.0.0)
39
+ i18n (0.5.0)
40
+ mail (2.2.15)
41
+ activesupport (>= 2.3.6)
42
+ i18n (>= 0.4.0)
43
+ mime-types (~> 1.16)
44
+ treetop (~> 1.4.8)
45
+ mime-types (1.16)
46
+ polyglot (0.3.1)
47
+ rack (1.2.1)
48
+ rack-mount (0.6.13)
49
+ rack (>= 1.0.0)
50
+ rack-test (0.5.7)
51
+ rack (>= 1.0)
52
+ rails (3.0.3)
53
+ actionmailer (= 3.0.3)
54
+ actionpack (= 3.0.3)
55
+ activerecord (= 3.0.3)
56
+ activeresource (= 3.0.3)
57
+ activesupport (= 3.0.3)
58
+ bundler (~> 1.0)
59
+ railties (= 3.0.3)
60
+ railties (3.0.3)
61
+ actionpack (= 3.0.3)
62
+ activesupport (= 3.0.3)
63
+ rake (>= 0.8.7)
64
+ thor (~> 0.14.4)
65
+ rake (0.8.7)
66
+ rspec (2.3.0)
67
+ rspec-core (~> 2.3.0)
68
+ rspec-expectations (~> 2.3.0)
69
+ rspec-mocks (~> 2.3.0)
70
+ rspec-core (2.3.1)
71
+ rspec-expectations (2.3.0)
72
+ diff-lcs (~> 1.1.2)
73
+ rspec-mocks (2.3.0)
74
+ rspec-rails (2.3.1)
75
+ actionpack (~> 3.0)
76
+ activesupport (~> 3.0)
77
+ railties (~> 3.0)
78
+ rspec (~> 2.3.0)
79
+ sqlite3 (1.3.3)
80
+ sqlite3-ruby (1.3.1)
81
+ thor (0.14.6)
82
+ treetop (1.4.9)
83
+ polyglot (>= 0.3.1)
84
+ tzinfo (0.3.24)
85
+
86
+ PLATFORMS
87
+ ruby
88
+
89
+ DEPENDENCIES
90
+ acts_as_fu
91
+ rails (~> 3.0.0)
92
+ rspec (~> 2.3.0)
93
+ rspec-rails (~> 2.3.0)
94
+ sqlite3
data/README ADDED
@@ -0,0 +1,30 @@
1
+ # fixjour 2 (to be renamed)
2
+
3
+ A rewrite I don't need to write.
4
+
5
+ The builder definitions are more like factory girl now.
6
+
7
+ ## Usage
8
+
9
+ require 'fixjour'
10
+
11
+ Fixjour do
12
+ define User do |user|
13
+ user.name = "Pat"
14
+ end
15
+ end
16
+
17
+ The methods generated are the same old Fixjour methods:
18
+
19
+ include Fixjour
20
+
21
+ new_user(:name => "Pat")
22
+ create_user(:name => "Pat")
23
+
24
+ That's it for now.
25
+
26
+ ## TODO
27
+
28
+ * counters (or sequences in Factory girl parlance)
29
+
30
+ (c) Copyright 2011 Pat Nakajima. All Rights Reserved.
@@ -0,0 +1,29 @@
1
+ module Fixjour
2
+ class Builder
3
+ def initialize(model, block)
4
+ @model, @block = model, block
5
+ end
6
+
7
+ def define
8
+ model, block = @model, @block
9
+ Fixjour.module_eval do
10
+ klass_name = model.model_name.singular
11
+
12
+ define_method("new_" + klass_name) do |*overrides|
13
+ instance = model.new
14
+ block.call(instance)
15
+ overrides.first && overrides.first.each do |key, val|
16
+ instance.send("#{key}=", val)
17
+ end
18
+ instance
19
+ end
20
+
21
+ define_method("create_" + klass_name) do |*overrides|
22
+ instance = send("new_#{klass_name}", *overrides)
23
+ instance.save!
24
+ instance
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,13 @@
1
+ module Fixjour
2
+ class DSL
3
+ include Fixjour
4
+
5
+ def initialize(block)
6
+ instance_eval(&block)
7
+ end
8
+
9
+ def define(model, &block)
10
+ Builder.new(model, block).define
11
+ end
12
+ end
13
+ end
data/lib/fixjour.rb ADDED
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+
3
+ require 'fixjour/dsl'
4
+ require 'fixjour/builder'
5
+
6
+ module Fixjour
7
+ def self.evaluate(&block)
8
+ DSL.new(block)
9
+ end
10
+ end
11
+
12
+ def Fixjour(&block)
13
+ if block_given?
14
+ Fixjour.evaluate(&block)
15
+ else
16
+ ::Fixjour
17
+ end
18
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe "Fixjour Builders" do
4
+ include Fixjour
5
+
6
+ it "defines builders" do
7
+ Fixjour do
8
+ define User do |user|
9
+ user.name = "Pat"
10
+ end
11
+
12
+ define Article do |article|
13
+ article.user = new_user(:name => "Pat")
14
+ end
15
+ end
16
+
17
+ user = new_user
18
+ user.new_record?.should be_true
19
+ user.should be_kind_of(User)
20
+ user.name.should == "Pat"
21
+
22
+ # Allow overrides
23
+ user = new_user(:name => "Brandon")
24
+ user.name.should == "Brandon"
25
+
26
+ # Define create_ method
27
+ user = create_user
28
+ user.new_record?.should be_false
29
+ user.should be_kind_of(User)
30
+
31
+ # It also allows overrides
32
+ user = create_user(:name => "Brandon", :age => 25)
33
+ user.new_record?.should be_false
34
+ user.name.should == "Brandon"
35
+ user.age.should == 25
36
+
37
+ # It allows associations
38
+ article = new_article
39
+ article.user.should_not be_nil
40
+ article.user.name.should == "Pat"
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'acts_as_fu'
4
+ require File.dirname(__FILE__) + "/../lib/fixjour"
5
+
6
+ build_model :users do
7
+ string :name
8
+ integer :age
9
+ attr_protected :age
10
+ end
11
+
12
+
13
+ build_model :articles do
14
+ integer :user_id
15
+ belongs_to :user
16
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixjour-2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Pat Nakajima
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-27 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: patnakajima@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - Gemfile
32
+ - Gemfile.lock
33
+ - README
34
+ - lib/fixjour.rb
35
+ - lib/fixjour/builder.rb
36
+ - lib/fixjour/dsl.rb
37
+ - spec/fixjour_spec.rb
38
+ - spec/spec_helper.rb
39
+ has_rdoc: true
40
+ homepage:
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.4.1
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Fixjour Again
73
+ test_files: []
74
+