fixjour-2 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -12,6 +12,11 @@ The builder definitions are more like factory girl now.
12
12
  define User do |user|
13
13
  user.name = "Pat"
14
14
  end
15
+
16
+ define Article do |article|
17
+ article.user = new_user
18
+ article.title = "This is a good one"
19
+ end
15
20
  end
16
21
 
17
22
  The methods generated are the same old Fixjour methods:
@@ -23,8 +28,26 @@ The methods generated are the same old Fixjour methods:
23
28
 
24
29
  That's it for now.
25
30
 
26
- ## TODO
31
+ ## What's New
32
+
33
+ I ripped out a bunch of stuff. Here are some things I don't need:
34
+
35
+ ### Overrides and `process`
36
+
37
+ The overrides hash in Fixjour was confusing to pretty much everybody I explained
38
+ it to, so it's gone now. PEACE.
39
+
40
+ ### valid_*_attributes
41
+
42
+ This was useful for controller tests. Controller tests are no longer useful
43
+ though. I like acceptance tests now. Hopefully you do too.
44
+
45
+ ### attr_protected attributes
46
+
47
+ They just work now. Don't worry about it.
48
+
49
+ ### Fixjour.verify!
27
50
 
28
- * counters (or sequences in Factory girl parlance)
51
+ It's gone now. Write tests for your builders and you're good to go.
29
52
 
30
53
  (c) Copyright 2011 Pat Nakajima. All Rights Reserved.
@@ -1,16 +1,17 @@
1
1
  module Fixjour
2
2
  class Builder
3
- def initialize(model, block)
4
- @model, @block = model, block
3
+ def initialize(model, options, &block)
4
+ @model, @options, @block = model, options, block
5
5
  end
6
6
 
7
7
  def define
8
- model, block = @model, @block
9
- Fixjour.module_eval do
10
- klass_name = model.model_name.singular
8
+ block = @block
9
+ klass = find_class
10
+ klass_name = klass.model_name.singular
11
11
 
12
+ Fixjour.module_eval do
12
13
  define_method("new_" + klass_name) do |*overrides|
13
- instance = model.new
14
+ instance = klass.new
14
15
  block.call(instance)
15
16
  overrides.first && overrides.first.each do |key, val|
16
17
  instance.send("#{key}=", val)
@@ -25,5 +26,13 @@ module Fixjour
25
26
  end
26
27
  end
27
28
  end
29
+
30
+ private
31
+
32
+ def find_class
33
+ @options[:class] || @model.is_a?(Symbol) ?
34
+ @model.to_s.classify.constantize :
35
+ @model
36
+ end
28
37
  end
29
38
  end
data/lib/fixjour/dsl.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  module Fixjour
2
2
  class DSL
3
3
  include Fixjour
4
+ include Fixjour::Counter
4
5
 
5
6
  def initialize(block)
6
7
  instance_eval(&block)
7
8
  end
8
9
 
9
- def define(model, &block)
10
- Builder.new(model, block).define
10
+ def define(model, options={}, &block)
11
+ Builder.new(model, options, &block).define
11
12
  end
12
13
  end
13
14
  end
data/lib/fixjour.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  $LOAD_PATH << File.dirname(__FILE__)
2
2
 
3
- require 'fixjour/dsl'
3
+ require 'fixjour/counter'
4
4
  require 'fixjour/builder'
5
+ require 'fixjour/dsl'
5
6
 
6
7
  module Fixjour
7
8
  def self.evaluate(&block)
data/spec/fixjour_spec.rb CHANGED
@@ -9,9 +9,14 @@ describe "Fixjour Builders" do
9
9
  user.name = "Pat"
10
10
  end
11
11
 
12
- define Article do |article|
12
+ define :article do |article|
13
13
  article.user = new_user(:name => "Pat")
14
14
  end
15
+
16
+ define :comment, :class => Article::Comment do |comment|
17
+ comment.text = "comment #{counter(:comment)}"
18
+ comment.article = new_article
19
+ end
15
20
  end
16
21
 
17
22
  user = new_user
@@ -38,5 +43,13 @@ describe "Fixjour Builders" do
38
43
  article = new_article
39
44
  article.user.should_not be_nil
40
45
  article.user.name.should == "Pat"
46
+
47
+ # It works with namespaces
48
+ comment = new_comment
49
+
50
+ # It works with counters
51
+ first_comment = new_comment
52
+ second_comment = new_comment
53
+ first_comment.text.should_not == second_comment.text
41
54
  end
42
55
  end
data/spec/spec_helper.rb CHANGED
@@ -9,8 +9,17 @@ build_model :users do
9
9
  attr_protected :age
10
10
  end
11
11
 
12
-
13
12
  build_model :articles do
14
13
  integer :user_id
15
14
  belongs_to :user
15
+ end
16
+
17
+ build_model :comments do
18
+ string :text
19
+ integer :article_id
20
+ belongs_to :article
21
+ end
22
+
23
+ class Article
24
+ Comment = ::Comment
16
25
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixjour-2
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pat Nakajima
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements: []
67
67
 
68
68
  rubyforge_project:
69
- rubygems_version: 1.4.1
69
+ rubygems_version: 1.6.2
70
70
  signing_key:
71
71
  specification_version: 3
72
72
  summary: Fixjour Again