Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove unnecessary whitespace from the project

  • Loading branch information...
commit 1fba1e9dbd7769fe6e442f796e271eeaba49cd26 1 parent 747aeb2
@smtlaissezfaire authored
Showing with 412 additions and 412 deletions.
  1. +4 −4 CHANGELOG.rdoc
  2. +23 −23 README.rdoc
  3. +1 −1  Rakefile
  4. +1 −1  TODO.rdoc
  5. +1 −1  VERSION
  6. +1 −1  contributions.rdoc
  7. +1 −1  etc/bug_reports/2007_09_28_linoj.txt
  8. +1 −1  etc/google_analytics
  9. +1 −1  etc/patches/2007_09_14_default_model_name_with_arguments.diff
  10. +79 −79 etc/patches/2007_10_14_active_record_specs.diff
  11. +2 −2 etc/patches/2007_10_14_protected_attributes.diff
  12. +10 −10 etc/patches/2007_10_14_send_patch.diff
  13. +1 −1  etc/patches/2007_10_14_spelling_error_in_comments.diff
  14. +34 −34 etc/patches/2007_10_17_protected_attributes_second_go.diff
  15. +31 −31 etc/patches/2007_10_18_README.diff
  16. +3 −3 etc/patches/2007_10_19_silence_migration.diff
  17. +8 −8 etc/patches/2007_10_25_changed_classify_to_camelize.diff
  18. +1 −1  etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch
  19. +8 −8 etc/patches/2007_11_20_string_random_refactor_and_extension.patch
  20. +8 −8 etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch
  21. +1 −1  lib/fixture_replacement.rb
  22. +16 −16 lib/fixture_replacement/attribute_builder.rb
  23. +3 −3 lib/fixture_replacement/class_methods.rb
  24. +3 −3 lib/fixture_replacement/method_generator.rb
  25. +1 −1  lib/fixture_replacement/version.rb
  26. +3 −3 philosophy_and_bugs.rdoc
  27. +1 −1  rake_tasks/code_quality.rb
  28. +1 −1  rake_tasks/docs.rb
  29. +1 −1  rake_tasks/gem.rb
  30. +21 −21 spec/fixture_replacement/attribute_builder_spec.rb
  31. +2 −2 spec/fixture_replacement/fixture_replacement_spec.rb
  32. +1 −1  spec/fixture_replacement/fixtures/classes.rb
  33. +1 −1  spec/fixture_replacement/fr_spec.rb
  34. +11 −11 spec/fixture_replacement/integration/attr_protected_attributes_spec.rb
  35. +1 −1  spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb
  36. +9 −9 spec/fixture_replacement/integration/attributes_from_spec_without_block.rb
  37. +12 −12 spec/fixture_replacement/integration/create_method_spec.rb
  38. +6 −6 spec/fixture_replacement/integration/cyclic_dependency_spec.rb
  39. +6 −6 spec/fixture_replacement/integration/default_warnings_spec.rb
  40. +5 −5 spec/fixture_replacement/integration/extend_spec.rb
  41. +9 −9 spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb
  42. +19 −19 spec/fixture_replacement/integration/new_method_spec.rb
  43. +7 −7 spec/fixture_replacement/integration/private_methods_spec.rb
  44. +3 −3 spec/fixture_replacement/integration/public_methods_spec.rb
  45. +8 −8 spec/fixture_replacement/integration/valid_attributes_spec.rb
  46. +15 −15 spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb
  47. +16 −16 spec/spec_helpers.rb
  48. +11 −11 test/unit/user_test.rb
View
8 CHANGELOG.rdoc
@@ -6,7 +6,7 @@
- Better Support for Reloading (call FR.reload! after calling reload! in the console or in your spec helper)
- default_* is gone. Use new_* instead.
- This will necessitate that declarations of the form validates_presence_of :association_id
+ This will necessitate that declarations of the form validates_presence_of :association_id
change to validates_presence_of :association
- attributes_for now yields the real active record object, not an OpenStruct, providing for increased
flexibility
@@ -15,7 +15,7 @@
attributes_for :event do |event, hash|
e.schedule = new_schedule(:event => event) unless hash[:schedule]
end
-
+
attributes_for :schedule do |schedule, hash|
s.event = new_event(:schedule => schedule) unless hash[:event]
end
@@ -42,14 +42,14 @@
- Add FR as an alias for FixtureReplacement. This should make it considerably easier to
use FR in the console:
-
+
smt$ ./script/console
Loading development environment (Rails 2.2.2)
>> include FR
=> Object
>> create_user
=> #<User id: 14 ... >
-
+
- Use better loading. Allow FixtureReplacement to be reloaded if cache_classes = false
- Removed generator, since db/example_data.rb is no longer required.
- Removed required db/example_data.rb. fixture_replacement can now be used outside of a rails
View
46 README.rdoc
@@ -2,21 +2,21 @@
== What is FixtureReplacement
-FixtureReplacement is a Rails[http://rubyonrails.org/] plugin that provides a simple way to
-quickly populate your test database with model objects without having to manage multiple,
-brittle fixture files. You can easily set up complex object graphs (with models which
+FixtureReplacement is a Rails[http://rubyonrails.org/] plugin that provides a simple way to
+quickly populate your test database with model objects without having to manage multiple,
+brittle fixture files. You can easily set up complex object graphs (with models which
reference other models) and add new objects on the fly.
-Not only can FixtureReplacement make your test data easier to maintain, it can also help
-to make your tests and specs much more readable and intention-revealing by allowing you
-to omit extraneous details and focus only on the attributes that are important for a
-particular behaviour. It works well with both RSpec[http://rspec.rubyforge.org/] and
+Not only can FixtureReplacement make your test data easier to maintain, it can also help
+to make your tests and specs much more readable and intention-revealing by allowing you
+to omit extraneous details and focus only on the attributes that are important for a
+particular behaviour. It works well with both RSpec[http://rspec.rubyforge.org/] and
Test::Unit[http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html].
== What's new since 2.0:
* default_* is gone in favor of new_*.
-* Cyclic dependencies are no longer an issue. The "overrides hash" (the hash passed to new_* or create_*) can now be processed.
+* Cyclic dependencies are no longer an issue. The "overrides hash" (the hash passed to new_* or create_*) can now be processed.
See CHANGELOG.rdoc + test suite for further changes.
@@ -46,15 +46,15 @@ Add the following to your <tt>test/test_helper.rb</tt> file:
=== Defining default attributes
-At the heart of FixtureReplacement is the <tt>db/example_data.rb</tt> file where you
+At the heart of FixtureReplacement is the <tt>db/example_data.rb</tt> file where you
define the default attributes for each of your test models. This example shows the default
attributes for a user:
module FixtureReplacement
-
+
attributes_for :user do |u|
password = random_string
-
+
u.value = "a value",
u.other = "other value",
u.another = random_string, # random string 10 characters long
@@ -63,19 +63,19 @@ attributes for a user:
u.password_confirmation = password,
u.associated_object = new_bar # expects attributes_for :bar to be setup
end
-
+
end
Note that:
-- A 'random_string' method is provided for attributes whose exact value isn't important; this means you can
+- A 'random_string' method is provided for attributes whose exact value isn't important; this means you can
create multiple, unique model instances
-- you can perform arbitrary set-up and execute any Ruby code prior to returning the hash
- (as shown here where a <tt>password</tt> is generated and then used for both the <tt>:password</tt> and
+- you can perform arbitrary set-up and execute any Ruby code prior to returning the hash
+ (as shown here where a <tt>password</tt> is generated and then used for both the <tt>:password</tt> and
<tt>:password_confirmation</tt> attributes)
-- a <tt>new_modelname</tt> method is automatically provided that allows you to set up dependent
+- a <tt>new_modelname</tt> method is automatically provided that allows you to set up dependent
model objects (in this case an instance of the <tt>Bar</tt> model)
-
+
=== Available methods
Based on the above definition FixtureReplacement makes the following methods available:
@@ -89,15 +89,15 @@ Based on the above definition FixtureReplacement makes the following methods ava
Overrides of specific attributes can be performed as follows:
- new_user(:thing => "overridden")
+ new_user(:thing => "overridden")
create_user(:thing => "overridden")
-
+
Overrides can also be used with associations:
scott = create_user(:username => "scott")
post = create_post(:user => scott)
-
-
+
+
=== attr_protected / attr_accessible
In the case that the model has an attr_protected field, FixtureReplacement
@@ -109,7 +109,7 @@ will assign the field as if it wasn't protected, which is convenient for testing
user = create_user(:username => "scott", :admin_status => true)
user.admin_status # => true
-
+
=== Validate your fixtures (thanks Fixjour)
Validate your fixture definitions after including it in the spec helper or test helper:
@@ -132,7 +132,7 @@ Validate your fixture definitions after including it in the spec helper or test
=== Using FixtureReplacement within <tt>script/console</tt>
- $ ./script/console
+ $ ./script/console
Loading development environment
>> include FR
=> Object
View
2  Rakefile
@@ -5,4 +5,4 @@ Dir.glob("rake_tasks/**/*.rb").each do |file|
end
desc 'Default: run unit tests (specs + tests).'
-task :default => [:spec, :test]
+task :default => [:spec, :test]
View
2  TODO.rdoc
@@ -19,4 +19,4 @@
- Update website info
- Update with github info
- Register Lighthouse project
-- Remove TODOs from Rubyforge tracker (http://rubyforge.org/tracker/?group_id=4556)
+- Remove TODOs from Rubyforge tracker (http://rubyforge.org/tracker/?group_id=4556)
View
2  VERSION
@@ -1 +1 @@
-3.0.0
+3.0.0
View
2  contributions.rdoc
@@ -44,4 +44,4 @@ Thanks to the following for making this software better:
- bug reports
- Bryan Helmkamp: Feedback on back associating models.
- Pat Nakajima: Wonderful ideas from Fixjour. Elimination of default_* methods in favor
- of new_* methods. validation of new instances.
+ of new_* methods. validation of new instances.
View
2  etc/bug_reports/2007_09_28_linoj.txt
@@ -2,7 +2,7 @@ Hi Scott,
I'm wondering if you have insight into this or if I should go ask somewhere else.
-I installed 2 plug-in today,
+I installed 2 plug-in today,
first fixture_replacement plugin
and been using it successfully
View
2  etc/google_analytics
@@ -3,4 +3,4 @@
<script type="text/javascript">
_uacct = "UA-3080808-2";
urchinTracker();
-</script>
+</script>
View
2  etc/patches/2007_09_14_default_model_name_with_arguments.diff
@@ -14,7 +14,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb
end
@@ -63,9 +64,9 @@
default_method = "default_#{model_name}".to_sym
-
+
fixture_module.module_eval do
- define_method(default_method) do
+ define_method(default_method) do |*args|
View
158 etc/patches/2007_10_14_active_record_specs.diff
@@ -7,9 +7,9 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
require File.dirname(__FILE__) + "/../spec_helper"
+require 'activesupport'
+require 'activerecord'
-
+
-# It would be better if these things were actual mocks/stubs
--# of ActiveRecord Classes.
+-# of ActiveRecord Classes.
-class ARBase
- class << self
- def create!(h={})
@@ -34,7 +34,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+class Alien < ActiveRecord::Base
+ belongs_to :gender
+end
-
+
- def initialize(hash={})
- @hash = hash
+ActiveRecord::Schema.define do
@@ -43,49 +43,49 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ t.string :other_key
+ t.integer :gender_id
end
--
+-
- attr_reader :hash
--
+-
- def gender # this would be a has_many call in rails
- 17
+ create_table :genders do |t|
+ t.string :sex
end
--
+-
- def save!
- @saved = true
+ create_table :aliens do |t|
+ t.integer :gender_id
end
--
+-
- def saved?
- @saved || false
-- end
--
+- end
+-
end
-
+
-class User < ARBase; end
-class Gender < ARBase; end
-class Alien < ARBase; end
+include FixtureReplacement
-
+
-
module FixtureReplacement
describe Generator, "creation" do
before :each do
@generator = Generator.new("user")
end
-
+
- it "should take a lowecase-model name as it's paramaters" do
+ it "should take a lowercase-model name as its paramaters" do
@generator.model_name.should == "user"
end
-
+
- it "should be able to take tell the name of model in string" do
+ it "should be able to take tell the name of model in string" do
@generator.model_name.to_s.should == "user"
end
-
+
@@ -84,16 +83,11 @@
FixtureReplacement.module_eval do
def user_attributes
@@ -94,31 +94,31 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ :key => "val"
}
end
- end
+ end
@generator = Generator.new("user")
--
+-
- @class = Class.new do
- include FixtureReplacement
- end
- @instance = @class.new
end
-
+
it "should generate the method default_user in the module" do
@@ -103,45 +97,34 @@
-
+
it "should return a ::FixtureReplacement::DelayedEvaluationProc" do
@generator.generate_default_method
- @instance.default_user.class.should == ::FixtureReplacement::DelayedEvaluationProc
+ default_user.class.should == ::FixtureReplacement::DelayedEvaluationProc
end
-
- it %(should return the special proc, which in turn should return an array
+
+ it %(should return the special proc, which in turn should return an array
of the name of the model ('user') if no params were given) do
@generator.generate_default_method
- @instance.default_user.call.should == ["user"]
+ default_user.call.should == ["user"]
end
-
+
it %(should return the special proc, which in turn should return an array
of the name of the model ('user') and the params given) do
@generator.generate_default_method
@@ -126,7 +126,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ default_user({:key => "hash"}).call.should == ["user", {:key => "hash"}]
end
end
-
+
describe Generator, "generate_create_method for User when user_attributes is defined (and valid)" do
- before :each do
- User.class_eval do
@@ -134,8 +134,8 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
- @saved = true
- end
- end
--
-+ before :each do
+-
++ before :each do
FixtureReplacement.module_eval do
def user_attributes
{
@@ -143,52 +143,52 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ :key => "val"
}
end
- end
+ end
@generator = Generator.new("user")
@generator.generate_new_method
@generator.generate_create_method
--
+-
- @class = Class.new do
- include FixtureReplacement
- end
-- @instance = @class.new
+- @instance = @class.new
end
-
+
it "should generate the method create_user in the module" do
@@ -150,38 +133,32 @@
-
+
it "should generate the method create_user which takes one parameter - a hash" do
@generator.generate_create_method
- @instance.create_user({:key => :value})
+ create_user({:key => "value"})
end
-
+
it "should return a user" do
@generator.generate_create_method
- @instance.create_user.should be_a_kind_of(User)
+ create_user.should be_a_kind_of(User)
end
-
+
- it "should return a user which has been saved (with create!)" do
+ it "should return a user which has been saved (with save!)" do
@generator.generate_create_method
- @instance.create_user.should be_saved
+ create_user.saved.should == true
end
-
+
it "should overwrite the hash parameters given" do
@generator.generate_create_method
-- @instance.create_user(:key => :value).hash.should == {:key => :value}
+- @instance.create_user(:key => :value).hash.should == {:key => :value}
+ create_user(:key => "value").key.should == "value"
end
-
+
it "should not overwrite the default hash parameters, if none are given" do
@generator.generate_create_method
- @instance.create_user.hash.should == {:key => :val}
+ create_user.key.should == "val"
end
end
-
+
describe Generator, "generate_create_method for User when user_attributes is defined (and valid)" do
before :each do
- User.class_eval do
@@ -196,7 +196,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
- @saved = true
- end
- end
--
+-
FixtureReplacement.module_eval do
def user_attributes
{
@@ -204,13 +204,13 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
@generator = Generator.new("user")
@generator.generate_new_method
@generator.generate_create_method
--
+-
- @class = Class.new do
- include FixtureReplacement
- end
-- @instance = @class.new
+- @instance = @class.new
end
-
+
it "should save the associated join models which have a default_* method (if it is not overwritten)" do
- created_user = @instance.create_user
- created_gender = created_user.hash[:gender]
@@ -218,7 +218,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ created_gender = create_user.gender
+ created_gender.sex.should == "Male"
end
-
+
it "should not save the associated join model, but not as the default_* method (in the case that it is overwritten)" do
- created_user = @instance.create_user(:gender => Gender.create!(:sex => "Female"))
- created_gender = created_user.hash[:gender]
@@ -227,7 +227,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ created_gender = created_user.gender
+ created_gender.sex.should == "Female"
end
-
+
- it "should call Gender.create! when the default_gender method is evaluated by default_gender" do
- gender = Gender.new
- Gender.should_receive(:create!).and_return gender
@@ -235,7 +235,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
+ create_user.gender.saved.should == true
end
-
+
- it "should not call Gender.create! if the default_gender is overwritten by another value (say, a string)" do
- Gender.should_not_receive(:create!)
- @instance.create_user(:gender => "a string")
@@ -243,16 +243,16 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ create_user(:gender => Gender.new).gender.saved.should_not == true
end
end
-
+
describe Generator, "generate_create_method for User when user_attributes is defined, but not valid" do
- before :each do
- User.class_eval do
- def save!
- @saved = true
- end
-- end
--
-+ before :each do
+- end
+-
++ before :each do
FixtureReplacement.module_eval do
def user_attributes
{
@@ -260,41 +260,41 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ :key => "val"
}
end
- end
+ end
@generator = Generator.new("user")
@generator.generate_new_method
@generator.generate_create_method
--
+-
- @class = Class.new do
- include FixtureReplacement
- end
-- @instance = @class.new
+- @instance = @class.new
end
-
+
it "should generate the method create_user in the module" do
@@ -265,22 +222,9 @@
-
+
it "should generate the method create_user which takes one parameter - a hash" do
@generator.generate_create_method
- @instance.create_user({:key => :value})
+ create_user({:key => "value"})
end
-
+
- it "should raise an error with a user which has been saved (with create!)" do
- User.class_eval do
- def save!
- raise
- end
- end
--
+-
- @generator.generate_create_method
- lambda {
-- @instance.create_user
+- @instance.create_user
- }.should raise_error
-- end
--
+- end
+-
end
-
+
describe Generator, "generate_new_method for User when user_attributes is defined" do
@@ -290,7 +234,7 @@
FixtureReplacement.module_eval do
@@ -304,65 +304,65 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ :key => "val"
}
end
-
+
@@ -302,12 +246,6 @@
- end
+ end
@generator = Generator.new("user")
@generator.generate_new_method
--
+-
- @class = Class.new do
- include FixtureReplacement
- end
-- @instance = @class.new
--
+- @instance = @class.new
+-
end
-
+
it "should respond to new_user in the module" do
@@ -316,19 +254,21 @@
-
+
it "should return a new User object" do
User.stub!(:new).and_return @user
- @instance.new_user.should == @user
+ new_user.should == @user
end
-
+
it "should return a new User object with the keys given in user_attributes" do
- @instance.new_user.hash.should == {:key => :val}
+ new_user.key.should == "val"
end
-
+
it "should over-write the User's hash with any hash given to new_user" do
- @instance.new_user(:key => :other_value).hash.should == {:key => :other_value}
+ new_user(:key => "other_value").key.should == "other_value"
end
-
+
it "should add any hash key-value pairs which weren't previously given in user_attributes" do
- @instance.new_user(:other_key => :other_value).hash.should == {:key => :val, :other_key => :other_value}
+ u = new_user(:other_key => "other_value")
+ u.key.should == "val"
+ u.other_key.should == "other_value"
- end
+ end
end
-
+
@@ -365,39 +305,30 @@
-
+
@generator = Generator.new("alien")
@generator.generate_new_method
--
+-
- @class = Class.new do
- include FixtureReplacement
- end
-- @instance = @class.new
+- @instance = @class.new
end
-
- it "should evaluate any of the default_* methods before returning (if no over-writing key is given)" do
+
+ it "should evaluate any of the default_* methods before returning (if no over-writing key is given)" do
- new_user = @instance.new_user
- new_gender = new_user.hash[:gender]
- new_gender.hash.should == {:sex => "Male"}
+ new_gender = new_user.gender
+ new_gender.sex.should == "Male"
end
-
+
it %(should evaluate any of the default_* methods before returning, with the hash params given to default_* method) do
- new_alien = @instance.new_alien
- new_gender = new_alien.hash[:gender]
@@ -370,20 +370,20 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ new_gender = new_alien.gender
+ new_gender.sex.should == "unknown"
end
-
+
it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
- Gender.should_receive(:create!)
- @instance.new_user
+ new_user.gender.saved.should == true
end
-
+
- it "should not call Gender.new if the default_gender is overwritten by another value (say, a string)" do
- Gender.should_not_receive(:create!)
- @instance.new_user(:gender => "a string")
+ it "should not call Gender.new if the default_gender is overwritten by another value" do
+ new_user(:gender => Gender.new).gender.saved.should_not == true
end
-
+
it "should be able to overwrite a default_* method" do
- new_user = @instance.new_user(:gender => Gender.create!(:sex => "Female"))
- created_gender = new_user.hash[:gender]
@@ -393,4 +393,4 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ created_gender.sex.should == "Female"
end
end
-
+
View
4 etc/patches/2007_10_14_protected_attributes.diff
@@ -5,12 +5,12 @@ Index: lib/fixture_replacement/fixture_replacement.rb
@@ -70,7 +70,9 @@
hash_given = args[0] || Hash.new
merged_hash = self.send(attributes_method).merge(hash_given)
- evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
+ evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
- obj = class_name.create!(evaluated_hash)
+ obj = class_name.new
+ evaluated_hash.each { |k, v| obj.update_attribute(k, v) }
+ obj.save!
- obj
+ obj
end
end
@@ -86,7 +88,9 @@
View
20 etc/patches/2007_10_14_send_patch.diff
@@ -5,12 +5,12 @@ Index: lib/fixture_replacement/fixture_replacement.rb
@@ -70,7 +70,9 @@
hash_given = args[0] || Hash.new
merged_hash = self.send(attributes_method).merge(hash_given)
- evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
+ evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
- obj = class_name.create!(evaluated_hash)
+ obj = class_name.new
+ evaluated_hash.each { |k, v| obj.send("#{k}=", v) }
+ obj.save!
- obj
+ obj
end
end
@@ -86,7 +88,9 @@
@@ -29,9 +29,9 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
--- spec/fixture_replacement/fixture_replacement_spec.rb (revision 31)
+++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy)
@@ -18,6 +18,14 @@
-
+
attr_reader :hash
-
+
+ def method_missing symbol, *args
+ if symbol.id2name =~ /\A(.+)=\z/
+ @hash[$~[1].to_sym] = *args
@@ -39,14 +39,14 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ super
+ end
+ end
-+
++
def gender # this would be a has_many call in rails
17
end
@@ -222,14 +230,14 @@
created_gender.hash.should == {:sex => "Female"}
end
-
+
- it "should call Gender.create! when the default_gender method is evaluated by default_gender" do
+ it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
gender = Gender.new
@@ -54,7 +54,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ Gender.should_receive(:save!).and_return gender
@instance.create_user
end
-
+
- it "should not call Gender.create! if the default_gender is overwritten by another value (say, a string)" do
- Gender.should_not_receive(:create!)
+ it "should not call Gender.save! if the default_gender is overwritten by another value (say, a string)" do
@@ -64,16 +64,16 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
end
@@ -385,12 +393,12 @@
end
-
+
it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
- Gender.should_receive(:create!)
+ Gender.should_receive(:save!)
@instance.new_user
end
-
+
it "should not call Gender.new if the default_gender is overwritten by another value (say, a string)" do
- Gender.should_not_receive(:create!)
+ Gender.should_not_receive(:save!)
@instance.new_user(:gender => "a string")
end
-
+
View
2  etc/patches/2007_10_14_spelling_error_in_comments.diff
@@ -4,7 +4,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb
+++ lib/fixture_replacement/fixture_replacement.rb (working copy)
@@ -22,7 +22,7 @@
end
-
+
# This uses a DelayedEvaluationProc, not a typical proc, for type checking.
- # It maybe absurd to try to store a proc in a database, but even if someone tries,
+ # It may be absurd to try to store a proc in a database, but even if someone tries,
View
68 etc/patches/2007_10_17_protected_attributes_second_go.diff
@@ -5,15 +5,15 @@ Index: lib/fixture_replacement/fixture_replacement.rb
@@ -70,7 +70,12 @@
hash_given = args[0] || Hash.new
merged_hash = self.send(attributes_method).merge(hash_given)
- evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
+ evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
- obj = class_name.create!(evaluated_hash)
-+
++
+ # we are NOT doing the following, because of attr_protected:
+ # obj = class_name.create!(evaluated_hash)
+ obj = class_name.new
+ evaluated_hash.each { |key, value| obj.send("#{key}=", value) }
+ obj.save!
- obj
+ obj
end
end
@@ -86,7 +91,11 @@
@@ -21,7 +21,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb
merged_hash = self.send(attributes_method).merge(hash_given)
evaluated_hash = Generator.merge_unevaluated_method(self, :create, merged_hash)
- class_name.new(evaluated_hash)
-+
++
+ # we are also doing the following because of attr_protected:
+ obj = class_name.new
+ evaluated_hash.each { |key, value| obj.send("#{key}=", value) }
@@ -36,13 +36,13 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
@@ -9,9 +9,88 @@
belongs_to :gender
end
-
+
+class Admin < ActiveRecord::Base
+ attr_protected :admin_status
+end
+
class Gender < ActiveRecord::Base; end
-
+
+
+
+
@@ -58,7 +58,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ }
+ end
+ end
-+
++
+ @generator = Generator.new("admin")
+ @generator.generate_create_method
+ end
@@ -68,24 +68,24 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ create_admin
+ }.should_not raise_error
+ end
-+
++
+ it "should have admin_status equal to the default value (when it has not been overwritten)" do
+ create_admin.admin_status.should == true
+ end
-+
++
+ it "should have admin_status equal to the overwritten value" do
+ create_admin(:admin_status => false).admin_status.should be_false
+ end
-+
++
+ it "should have the other attributes assigned when the attr_value has been overwritten" do
+ create_admin(:admin_status => false).name.should == "Scott"
+ end
+
+ it "should have the other attributes assigned even when the attr_value has not been overwritten" do
+ create_admin.name.should == "Scott"
-+ end
++ end
+ end
-+
++
+ describe "new_user with attr_protected attributes" do
+ before :each do
+ FixtureReplacement.module_eval do
@@ -96,59 +96,59 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ }
+ end
+ end
-+
++
+ @generator = Generator.new("admin")
+ @generator.generate_new_method
+ end
-+
++
+ it "should have admin_status equal to the default value (when it has not been overwritten)" do
+ new_admin.admin_status.should == true
+ end
-+
++
+ it "should have admin_status equal to the overwritten value" do
+ new_admin(:admin_status => false).admin_status.should be_false
+ end
-+
++
+ it "should have the other attributes assigned when the attr_value has been overwritten" do
+ new_admin(:admin_status => false).name.should == "Scott"
+ end
+
+ it "should have the other attributes assigned even when the attr_value has not been overwritten" do
+ new_admin.name.should == "Scott"
-+ end
++ end
+ end
+
-+
++
describe Generator, "creation" do
before :each do
@generator = Generator.new("user")
@@ -121,9 +200,14 @@
create_user.should_not be_a_new_record
end
-
+
- it "should save the user with create!" do
+ it "should save the user with save!" do
@generator.generate_create_method
- User.should_receive(:create!).with({:key => "val"})
-+
++
+ @user = mock('User', :null_object => true)
-+ @user.stub!(:save!).and_return true
++ @user.stub!(:save!).and_return true
+ User.stub!(:new).and_return @user
-+
++
+ @user.should_receive(:save!).with(no_args)
create_user
end
-
+
@@ -175,13 +259,20 @@
created_gender.sex.should == "Female"
end
-
+
- it "should call Gender.create! when the default_gender method is evaluated by default_gender" do
- Gender.should_receive(:create!).with({:sex => "Male"})
+ it "should call save! when the default_gender method is evaluated by default_gender" do
+ @gender = mock('Gender', :null_object => true)
+ Gender.stub!(:new).and_return @gender
-+
++
+ @user = mock('User', :null_object => true)
+ User.stub!(:new).and_return @user
+ @user.stub!(:gender=).and_return @gender
@@ -156,7 +156,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ @gender.should_receive(:save!).with(no_args)
create_user
end
-
+
- it "should not call Gender.create! if the default_gender is overwritten by another value" do
- Gender.should_not_receive(:create!)
+ it "should not call Gender.save! if the default_gender is overwritten by another value" do
@@ -167,7 +167,7 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
@@ -324,18 +415,24 @@
new_gender.sex.should == "unknown"
end
-
+
- it "should call Gender.create! when the default_gender method is evaluated by default_gender" do
- Gender.should_receive(:create!).with({:sex => "Male"})
+ it "should call Gender.save! when the default_gender method is evaluated by default_gender" do
@@ -176,18 +176,18 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+ @user = mock('User')
+ @user.stub!(:gender=).and_return @gender
+ User.stub!(:new).and_return @user
-+
++
+ @gender.should_receive(:save!)
new_user
end
-
+
- it "should not call Gender.create! if the default_gender is overwritten by another value" do
- Gender.should_not_receive(:create!)
+ it "should not call Gender.save! if the default_gender is overwritten by another value" do
+ Gender.should_not_receive(:save!)
new_user(:gender => Gender.new)
end
-
+
it "should be able to overwrite a default_* method" do
- Gender.should_not_receive(:create!).with({:sex => "Male"})
+ Gender.should_not_receive(:save!)
@@ -201,12 +201,12 @@ Index: spec/spec_helper.rb
@@ -21,6 +21,11 @@
t.column :gender_id, :string
end
-
+
+ create_table :admins do |t|
+ t.column :admin_status, :boolean
+ t.column :name, :string
+ end
-+
++
end
-
-
+
+
View
62 etc/patches/2007_10_18_README.diff
@@ -4,25 +4,25 @@ Index: README
+++ README (working copy)
@@ -1,32 +1,92 @@
= FixtureReplacement
-
+
-=== How to use FixtureReplacement
+== What is FixtureReplacement
-
+
-Full Documentation is coming, when time permits. For now, watch this screencast (and forward
-through my stupidity):
+FixtureReplacement is a Rails[http://rubyonrails.org/] plugin that provides a simple way to quickly populate your test database with model objects without having to manage multiple, brittle fixture files. You can easily set up complex object graphs (with models which reference other models) and add new objects on the fly.
-
+
-http://railsnewbie.com/files/fixture_replacement_demo.mov
+Not only can FixtureReplacement make your test data easier to maintain, it can also help to make your tests and specs much more readable and intention-revealing by allowing you to omit extraneous details and focus only on the attributes that are important for a particular behaviour. It works well with both RSpec[http://rspec.rubyforge.org/] and Test::Unit[http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/classes/Test/Unit.html].
-
+
-There is also some documentation at the following link, although the screencast is still advised:
+== How to use FixtureReplacement
-
+
-http://wincent.com/knowledge-base/FixtureReplacement_cheatsheet
+=== Defining default attributes
-
+
+At the heart of FixtureReplacement is the <tt>db/example_data.rb</tt> file where you define the default attributes for each of your test models. This example shows a <tt>user_attributes</tt> method that returns the attributes for an instance of the <tt>User</tt> model:
-
+
-=== Installation
+ module FixtureReplacement
+ def user_attributes
@@ -38,7 +38,7 @@ Index: README
+ }
+ end
+ end
-
+
+Note that:
+
+- the method returns a hash of attributes
@@ -59,7 +59,7 @@ Index: README
+
+Overrides of specific attributes can be performed as follows:
+
-+ new_user(:thing => "overridden")
++ new_user(:thing => "overridden")
+ create_user(:thing => "overridden")
+
+=== Screencast
@@ -71,22 +71,22 @@ Index: README
+== Installation
+
ruby script/plugin install http://thmadb.com/public_svn/plugins/fixture_replacement/
-
+
Or use externals:
-
+
ruby script/plugin install -x http://thmadb.com/public_svn/plugins/fixture_replacement/
-
+
-Run the generator if you don't have the file db/example_data.rb
+Run the generator if you don't have the file <tt>db/example_data.rb</tt>:
-
+
ruby script/generate fixture_replacement
-
+
+=== Using from within <tt>script/console</tt>
-
+
-=== Running the Specs/Tests for FixtureReplacement
+ % script/console
+ >> include FixtureReplacement
-
+
+=== Using from with RSpec
+
+Add the following to your <tt>spec/spec_helper.rb</tt> file:
@@ -101,37 +101,37 @@ Index: README
+
+== Running the Specs/Tests for FixtureReplacement
+
- You will need rspec (version 1.0.8 or later) to run the specs, as well as the sqlite3-ruby gem
+ You will need rspec (version 1.0.8 or later) to run the specs, as well as the sqlite3-ruby gem
(and sqlite3 installed):
-
+
@@ -37,16 +97,16 @@
-
+
% cd vendor/plugins/fixture_replacement
-
+
-Then run with rake
+Then run with <tt>rake<tt>
-
+
% rake
-
+
-=== Specdocs
+== Specdocs
-
+
Specdocs can be found here[http://replacefixtures.rubyforge.org/specdoc.html]
-
-
+
+
-=== Patches, Contributions:
+== Patches, Contributions:
-
+
Thanks to the following:
-
+
@@ -62,8 +122,7 @@
-
+
If you would like to change how this software works, please submit a patch with specs to scott@railsnewbie.com
-
+
+== License
-
+
-=== License
-
- This software is released under the MIT License. See the license agreement
+ This software is released under the MIT License. See the license agreement
-in lib/fixture_replacement.rb
+in <tt>lib/fixture_replacement.rb</tt>
View
6 etc/patches/2007_10_19_silence_migration.diff
@@ -3,10 +3,10 @@ Index: spec/spec_helper.rb
--- spec/spec_helper.rb (revision 65)
+++ spec/spec_helper.rb (working copy)
@@ -5,6 +5,7 @@
-
+
ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
-
+
+ActiveRecord::Migration.verbose = false
ActiveRecord::Schema.define do
-
+
create_table :users do |t|
View
16 etc/patches/2007_10_25_changed_classify_to_camelize.diff
@@ -3,13 +3,13 @@ Index: lib/fixture_replacement/fixture_replacement.rb
--- lib/fixture_replacement/fixture_replacement.rb (revision 70)
+++ lib/fixture_replacement/fixture_replacement.rb (working copy)
@@ -40,7 +40,7 @@
-
+
def initialize(method_name, fixture_mod=FixtureReplacement)
@model_name = method_name
- @model_class = method_name.classify
+ @model_class = method_name.camelize
@fixture_module = fixture_mod
-
+
add_to_class_singleton(@model_class)
Index: spec/fixture_replacement/fixture_replacement_spec.rb
===================================================================
@@ -17,22 +17,22 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb
+++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy)
@@ -14,6 +14,7 @@
end
-
+
class Gender < ActiveRecord::Base; end
+class Actress < ActiveRecord::Base; end
-
-
-
+
+
+
@@ -118,6 +119,12 @@
}.should raise_error
end
-
+
+ it "should not raise an error if the model ends with 's'" do
+ lambda {
+ Generator.new("actress")
+ }.should_not raise_error
+ end
-+
++
it "should be able to respond to generate_default_method" do
@generator.should respond_to(:generate_default_method)
end
View
2  etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch
@@ -8,6 +8,6 @@ Index: vendor/plugins/fixture_replacement/generators/fixture_replacement/fixture
-require 'config/environment'
+require 'config/environment' unless RAILS_GEM_VERSION
+require 'config/boot' unless RAILS_ROOT
-
+
class FixtureReplacementGenerator < Rails::Generator::Base
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
View
16 etc/patches/2007_11_20_string_random_refactor_and_extension.patch
@@ -7,15 +7,15 @@ Index: lib/fixture_replacement/string.rb
+ def random_chr
+ self[rand(size)].chr
+ end
-+
++
+ def random_str(length=10)
+ (1..length).collect {random_chr}.join
+ end
-+
++
+ def formatted_random_str(format, length=10)
+ format.split(/(%s)/).map {|str| str.sub('%s', random_str(length))}.join
+ end
-
+
-class String
def self.random(length=10)
- chars = ("a".."z").to_a
@@ -24,7 +24,7 @@ Index: lib/fixture_replacement/string.rb
- return string
+ ("a".."z").sort.join.random_str(length)
end
-+
++
+ def self.formatted_random(format, length=10)
+ ("a".."z").sort.join.formatted_random_str(format, length)
+ end
@@ -35,7 +35,7 @@ Index: spec/fixture_replacement/extentions_spec.rb
--- spec/fixture_replacement/extentions_spec.rb (revision 83)
+++ spec/fixture_replacement/extentions_spec.rb (working copy)
@@ -2,7 +2,9 @@
-
+
describe "String.random" do
it "should not be the same as another randomly generated string" do
- String.random.should_not == String.random
@@ -43,14 +43,14 @@ Index: spec/fixture_replacement/extentions_spec.rb
+ String.random.should_not == String.random
+ end
end
-
+
it "should by default be 10 characters long" do
@@ -12,9 +14,51 @@
it "should be able to specify the length of the random string" do
String.random(100).size.should == 100
end
--
-+
+-
++
it "should only generate lowercase letters" do
- s = String.random(100)
- s.upcase.should == s.swapcase
View
16 etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch
@@ -7,11 +7,11 @@ Index: lib/fixture_replacement/string.rb
+ def random_chr
+ self[rand(size)].chr
+ end
-+
++
+ def random_str(length=10)
+ (1..length).collect {random_chr}.join
+ end
-+
++
+ def formatted_random_str(format, length=10)
+ result = format.dup
+ while result.match(/(%(\d*)s)/) do
@@ -19,7 +19,7 @@ Index: lib/fixture_replacement/string.rb
+ end
+ result
+ end
-
+
-class String
def self.random(length=10)
- chars = ("a".."z").to_a
@@ -28,7 +28,7 @@ Index: lib/fixture_replacement/string.rb
- return string
+ ("a".."z").sort.join.random_str(length)
end
-+
++
+ def self.formatted_random(format, length=10)
+ ("a".."z").sort.join.formatted_random_str(format, length)
+ end
@@ -39,7 +39,7 @@ Index: spec/fixture_replacement/extentions_spec.rb
--- spec/fixture_replacement/extentions_spec.rb (revision 83)
+++ spec/fixture_replacement/extentions_spec.rb (working copy)
@@ -2,7 +2,9 @@
-
+
describe "String.random" do
it "should not be the same as another randomly generated string" do
- String.random.should_not == String.random
@@ -47,14 +47,14 @@ Index: spec/fixture_replacement/extentions_spec.rb
+ String.random.should_not == String.random
+ end
end
-
+
it "should by default be 10 characters long" do
@@ -12,9 +14,51 @@
it "should be able to specify the length of the random string" do
String.random(100).size.should == 100
end
--
-+
+-
++
it "should only generate lowercase letters" do
- s = String.random(100)
- s.upcase.should == s.swapcase
View
2  lib/fixture_replacement.rb
@@ -13,4 +13,4 @@ class InvalidInstance < StandardError; end
load "fr.rb"
-FixtureReplacement.load_example_data
+FixtureReplacement.load_example_data
View
32 lib/fixture_replacement/attribute_builder.rb
@@ -12,20 +12,20 @@ def validate_instances!
def instances
@instances ||= []
end
-
+
def add_instance(instance)
instances << instance
end
-
+
def clear_out_instances!
@instances = nil
end
-
+
def find_by_fixture_name(arg)
instances.detect { |instance| instance.fixture_name == arg }
end
end
-
+
def initialize(fixture_name, options={}, &block)
options.symbolize_keys!
@@ -38,14 +38,14 @@ def initialize(fixture_name, options={}, &block)
self.class.add_instance(self)
end
-
+
attr_reader :fixture_name
attr_reader :from
def active_record_class
@active_record_class ||= find_active_record_class
end
-
+
def instantiate(hash_to_merge = {}, instance = active_record_class.new)
returning instance do
instantiate_parent_fixture(instance)
@@ -53,7 +53,7 @@ def instantiate(hash_to_merge = {}, instance = active_record_class.new)
add_given_keys(instance, hash_to_merge)
end
end
-
+
def validate!
new_instance = instantiate
@@ -65,7 +65,7 @@ def validate!
end
private
-
+
class InvalidKeyError < StandardError; end
def check_valid_keys(options_given, valid_keys)
@@ -79,7 +79,7 @@ def check_valid_keys(options_given, valid_keys)
def instantiate_parent_fixture(instance)
derived_fixture.instantiate({}, instance) if derived_fixture?
end
-
+
def call_attribute_body(instance, hash_to_merge)
if @attributes_proc.arity == 2
@attributes_proc.call(instance, hash_to_merge)
@@ -87,29 +87,29 @@ def call_attribute_body(instance, hash_to_merge)
@attributes_proc.call(instance)
end
end
-
+
def add_given_keys(instance, hash_to_merge)
hash_to_merge.each do |key, value|
instance.send("#{key}=", value)
end
end
-
+
def find_derived_fixture
self.class.find_by_fixture_name(from)
end
-
+
def derived_fixture
@derived_fixture ||= find_derived_fixture
end
-
+
def derived_fixture?
derived_fixture ? true : false
end
-
+
def constantize(symbol)
symbol.to_s.camelize.constantize
end
-
+
def find_active_record_class
if @class
@class
@@ -126,4 +126,4 @@ def find_active_record_class
end
end
end
-end
+end
View
6 lib/fixture_replacement/class_methods.rb
@@ -8,7 +8,7 @@ def attributes_for(fixture_name, options={}, &block)
def validate!
AttributeBuilder.validate_instances!
end
-
+
def random_string(length=10)
chars = ("a".."z").to_a
string = ""
@@ -30,9 +30,9 @@ def reload!
AttributeBuilder.clear_out_instances!
load File.expand_path(File.dirname(__FILE__) + "/../fixture_replacement.rb")
end
-
+
private
-
+
# Any user defined instance methods need the module's class scope to be
# accessible inside the block given to attributes_for
#
View
6 lib/fixture_replacement/method_generator.rb
@@ -4,11 +4,11 @@ def initialize(builder, evaluation_module)
@builder = builder
@evaluation_module = evaluation_module
end
-
+
def generate_methods
builder = @builder
builder_name = builder.fixture_name
-
+
@evaluation_module.module_eval do
define_method("valid_#{builder_name}_attributes") do |*args|
obj = __send__ "new_#{builder_name}"
@@ -20,7 +20,7 @@ def generate_methods
obj.save!
obj
end
-
+
define_method("new_#{builder_name}") do |*args|
new_object = builder.instantiate(*args)
end
View
2  lib/fixture_replacement/version.rb
@@ -4,7 +4,7 @@ module Version
MAJOR = 3
MINOR = 0
TINY = 0
-
+
version_string = "#{MAJOR}.#{MINOR}.#{TINY}"
version_string << " RC#{RELEASE_CANDIDATE}" if defined?(RELEASE_CANDIDATE)
VERSION = version_string
View
6 philosophy_and_bugs.rdoc
@@ -1,6 +1,6 @@
== Motivation Behind FixtureReplacement
-As Dan Manges has outlined in his blog post, "Fixing Fixtures with Factory" (http://www.dcmanges.com/blog/38),
+As Dan Manges has outlined in his blog post, "Fixing Fixtures with Factory" (http://www.dcmanges.com/blog/38),
this approach to generating test data has a number of advantages:
- The factory provides default values and relationships
@@ -70,7 +70,7 @@ data is often helpful. Consider the following snippets of psudo-code (along wit
@user_one.friends.should == [@user_two]
end
-Notice that the above test adds a lot of extra noise in getting valid users into the database; The test, however, doesn't care what the usernames are, that the password is a good one, that the password matches the password confirmation, and so on. The point of the test is not to check those things, but rather that a friendship can be established.
+Notice that the above test adds a lot of extra noise in getting valid users into the database; The test, however, doesn't care what the usernames are, that the password is a good one, that the password matches the password confirmation, and so on. The point of the test is not to check those things, but rather that a friendship can be established.
Here would be a similar test with the FixtureReplacement:
@@ -125,4 +125,4 @@ Another approach is to look to external sources to speed up your test suite:
- running tests individually, or per file
- A faster machine
-If you have other ideas for speeding up your test suite, I'm all ears.
+If you have other ideas for speeding up your test suite, I'm all ears.
View
2  rake_tasks/code_quality.rb
@@ -34,4 +34,4 @@ def sloc
File.open(File.dirname(__FILE__) + "/doc/lines_of_code.txt", "w") do |f|
f << sloc
end
-end
+end
View
2  rake_tasks/docs.rb
@@ -56,4 +56,4 @@ def create_doc_directory
end
desc 'Create the specdoc + rdoc'
-task :build_docs => [:rerdoc, :specdoc, :rcov, :flog_to_disk]
+task :build_docs => [:rerdoc, :specdoc, :rcov, :flog_to_disk]
View
2  rake_tasks/gem.rb
@@ -24,4 +24,4 @@
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
-end
+end
View
42 spec/fixture_replacement/attribute_builder_spec.rb
@@ -10,96 +10,96 @@ module FixtureReplacement
a = AttributeBuilder.new(:foo)
AttributeBuilder.instances.should == [a]
end
-
+
it "should have no instances when none have been created" do
AttributeBuilder.instances.should == []
end
-
+
it "should have two instances when two have been created" do
a1 = AttributeBuilder.new(:foo)
a2 = AttributeBuilder.new(:foo)
AttributeBuilder.instances.should == [a1, a2]
end
-
+
it "should have the fixture name as accessible" do
a1 = AttributeBuilder.new(:foo)
a1.fixture_name.should == :foo
end
-
+
it "should have the from attribute as nil, if none provided" do
a1 = AttributeBuilder.new(:foo)
a1.from.should be_nil
end
-
+
it "should have the from attribute as the symbol of the attribute from which it derives" do
a1 = AttributeBuilder.new(:foo, :from => :bar)
a1.from.should == :bar
end
-
+
it "should be able to find the Attribute by fixture name" do
a = AttributeBuilder.new(:baz)
AttributeBuilder.find_by_fixture_name(:baz).should == a
end
-
+
it "should find no attributes for fixture_name :baz, if it was never created" do
a = AttributeBuilder.new(:bar)
AttributeBuilder.find_by_fixture_name(:baz).should be_nil
end
-
+
it "should find no attributes for fixture_name :baz, if no fixture at all was ever created" do
AttributeBuilder.find_by_fixture_name(:baz).should be_nil
end
-
+
it "should have the class name if specified" do
AttributeBuilder.new(:foo, :class => Object).active_record_class.should == Object
end
-
+
it "should use the class name of the fixture_name, camel-cased, if the class is unspecified, and the fixture uninherited" do
AttributeBuilder.new(:object).active_record_class.should == Object
end
-
+
it "should use the class name of the inherited attribute, if specified" do
AttributeBuilder.new(:foo, :class => Object)
AttributeBuilder.new(:bar, :from => :foo).active_record_class.should == Bar
end
-
+
it "should prefer the constantized name to the derived name" do
AttributeBuilder.new(:user)
AttributeBuilder.new(:admin, :from => :user).active_record_class.should == Admin
end
-
+
it "should use the derived name if the constantized name fails (doesn't exist)" do
AttributeBuilder.new(:foo)
no_constant = AttributeBuilder.new(:no_constant, :from => :foo)
no_constant.active_record_class.should == Foo
end
-
+
it "should raise a name error if it has no class, the name can't be constantized, and is derived, but the derived class can't be constantized" do
builder_one = AttributeBuilder.new(:does_not_exist)
builder_two = AttributeBuilder.new(:also_does_not_exist, :from => :does_not_exist)
-
+
lambda {
builder_two.active_record_class
}.should raise_error(NameError)
end
-
+
it "should not raise an error if the model ends with 's'" do
AttributeBuilder.new(:actress).active_record_class.should == Actress
end
-
+
it "should allow a string key" do
AttributeBuilder.new(:admin, "from" => :user).active_record_class.should == Admin
end
-
+
it "should allow a string name for the builder" do
AttributeBuilder.new("admin").active_record_class.should == Admin
end
-
+
it "should store the from key as a symbol, even when passed a string" do
builder = AttributeBuilder.new(:admin, "from" => "user")
builder.from.should == :user
end
-
+
it "should convert the fixture name to a symbol" do
builder = AttributeBuilder.new("admin")
builder.fixture_name.should == :admin
@@ -158,5 +158,5 @@ module FixtureReplacement
}.should raise_error(FixtureReplacement::InvalidInstance, "new_address_with_valid_city_and_state is not valid! - Errors: [city: can't be blank], [state: can't be blank]")
end
end
- end
+ end
end
View
4 spec/fixture_replacement/fixture_replacement_spec.rb
@@ -5,7 +5,7 @@
before do
@fr = FixtureReplacement
end
-
+
it "should not be the same as another randomly generated string" do
@fr.random_string.should_not == @fr.random_string
end
@@ -87,7 +87,7 @@ def use_rails_root(rails_root, &block)
FixtureReplacement.reload!
end
end
-
+
describe "method_added" do
it "should be private" do
FixtureReplacement.should_not respond_to(:method_added)
View
2  spec/fixture_replacement/fixtures/classes.rb
@@ -75,4 +75,4 @@ class AddressWithValidCityAndState < ActiveRecord::Base
validates_presence_of :city
validates_presence_of :state
end
-end
+end
View
2  spec/fixture_replacement/fr_spec.rb
@@ -4,4 +4,4 @@
it "should alias FixtureReplacement" do
FR.should equal(FixtureReplacement)
end
-end
+end
View
22 spec/fixture_replacement/integration/attr_protected_attributes_spec.rb
@@ -10,32 +10,32 @@ module FixtureReplacement
end
end
end
-
+
it "should not complain when an apparent mass assignment has happened with default values" do
lambda {
@obj.create_admin
}.should_not raise_error
end
-
+
it "should not be a new record" do
@obj.create_admin.should_not be_a_new_record
end
-
+
it "should have admin_status equal to the default value (when it has not been overwritten)" do
@obj.create_admin.admin_status.should == true
end
-
+
it "should have admin_status equal to the overwritten value" do
@obj.create_admin(:admin_status => false).admin_status.should be_false
end
-
+
it "should have the other attributes assigned when the attr_value has been overwritten" do
@obj.create_admin(:admin_status => false).name.should == "Scott"
end
-
+
it "should have the other attributes assigned even when the attr_value has not been overwritten" do
@obj.create_admin.name.should == "Scott"
- end
+ end
end
describe "new_user with attr_protected attributes" do
@@ -47,7 +47,7 @@ module FixtureReplacement
end
end
end
-
+
it "should return a new Admin with new_admin" do
@obj.new_admin.should be_a_kind_of(Admin)
end
@@ -66,6 +66,6 @@ module FixtureReplacement
it "should have the other attributes assigned even when the attr_value has not been overwritten" do
@obj.new_admin.name.should == "Scott"
- end
- end
-end
+ end
+ end
+end
View
2  spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb
@@ -11,4 +11,4 @@ module FixtureReplacement
":class_name is not a valid option to attributes_for. Valid keys are: [:from, :class]")
end
end
-end
+end
View
18 spec/fixture_replacement/integration/attributes_from_spec_without_block.rb
@@ -3,7 +3,7 @@
module FixtureReplacement
describe AttributeBuilder do
include FixtureReplacementControllerHelper
-
+
before :each do
@obj = use_module do
attributes_for :user do |u|
@@ -20,33 +20,33 @@ module FixtureReplacement
end
end
end
-
+
models = "user", "foo", "scott"
-
+
models.each do |model|
it "should have the new_#{model} method as a (module) method on the module" do
@obj.should respond_to("new_#{model}")
end
-
+
it "should have the new_#{model} method as a private method in the test case" do
@obj.private_methods.should include("new_#{model}")
- end
+ end
it "should have the create_#{model} method as a private method in the test case" do
@obj.private_methods.should include("create_#{model}")
end
-
+
it "should have the create_#{model} method as a (module) method on the module" do
@obj.should respond_to("create_#{model}")
end
end
-
+
it "should have the username as a string (for User) for new_user" do
@obj.new_user.username.class.should == String
end
-
+
it "should have the username as a string (for User) for create_user" do
@obj.create_user.username.class.should == String
end
end
-end
+end
View
24 spec/fixture_replacement/integration/create_method_spec.rb
@@ -6,56 +6,56 @@ module FixtureReplacement
obj = use_module do
attributes_for :user
end
-
+
obj.create_user.should be_a_kind_of(User)
end
-
+
it "should use the given class" do
obj = use_module do
attributes_for :foo, :class => User
end
-
+
obj.create_foo.should be_a_kind_of(User)
end
-
+
it "should find the correct class name" do
obj = use_module do
attributes_for :admin
end
-
+
obj.create_admin.should be_a_kind_of(Admin)
end
-
+
it "should over-write the User's hash with any hash given to create_user" do
obj = use_module do
attributes_for :user do |u|
u.key = "val"
end
end
-
+
obj.create_user(:key => "other_value").key.should == "other_value"
end
-
+
it "should add any hash key-value pairs which weren't previously given in user_attributes" do
obj = use_module do
attributes_for :user do |u|
u.key = "val"
end
end
-
+
user = obj.create_user(:other_key => "other_value")
user.key.should == "val"
user.other_key.should == "other_value"
end
-
+
it "should not be saved to the database" do
obj = use_module do
attributes_for :user do |u|
u.key = "val"
end
end
-
+
obj.create_user.should_not be_a_new_record
end
end
-end
+end
View
12 spec/fixture_replacement/integration/cyclic_dependency_spec.rb
@@ -6,27 +6,27 @@
attributes_for :event do |e, hash|
e.schedule = new_schedule(:event => e) unless hash[:schedule]
end
-
+
attributes_for :schedule do |s, hash|
s.event = new_event(:schedule => s) unless hash[:event]
end
end
end
-
+
it "should allow them" do
@mod.new_event.should be_a_kind_of(Event)
end
-
+
it "should associate an event with a schedule" do
@mod.new_event.schedule.should be_a_kind_of(Schedule)
end
-
+
it "should associate a schedule with an event" do
@mod.new_schedule.event.should be_a_kind_of(Event)
end
-
+
it "should back associate" do
schedule = @mod.new_schedule
schedule.event.schedule.should == schedule
end
-end
+end
View
12 spec/fixture_replacement/integration/default_warnings_spec.rb
@@ -4,26 +4,26 @@
before do
@mod = use_module do
attributes_for :post
-
+
attributes_for :comment
end
end
-
+
it "should warn when using default_" do
Kernel.should_receive(:warn).with("default_post has been deprecated. Please replace instances of default_post with the new_post method")
@mod.default_post
end
-
+
it "should use the correct builder name" do
Kernel.should_receive(:warn).with("default_comment has been deprecated. Please replace instances of default_comment with the new_comment method")
@mod.default_comment
end
-
+
it "should return a new instance" do
Kernel.stub!(:warn).and_return nil
-
+
post = @mod.default_post
post.should be_a_kind_of(Post)
post.should be_a_new_record
end
-end
+end
View
10 spec/fixture_replacement/integration/extend_spec.rb
@@ -5,19 +5,19 @@ module FixtureReplacement
it "should not create the create_* method in every instance of the class" do
mod = Module.new do
extend FixtureReplacement::ClassMethods
-
+
attributes_for :user do |x|
x.first_name = "Scott"
end
end
-
+
o1 = Object.new
o1.extend mod
Object.new.should_not respond_to(:create_user)
end
end
-
+
describe "including an object" do
it "should include methods into instances of the class" do
mod = Module.new do
@@ -30,8 +30,8 @@ module FixtureReplacement
klass = Class.new { include mod }
obj = klass.new
-
+
obj.should respond_to(:create_user)
end
end
-end
+end
View
18 spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb
@@ -28,37 +28,37 @@ module FixtureReplacement
it "should have the fixture create_subscriber" do
@obj.should respond_to(:create_subscriber)
end
-
+
it "should have the fixture create_subscription" do
@obj.should respond_to(:create_subscription)
end
-
+
it "should be able to create a new subscriber" do
lambda {
@obj.create_subscriber
}.should_not raise_error
end
-
+
it "should have the subscriber with the default subscription" do
subscriber = @obj.create_subscriber
subscriber.should have(1).subscription
subscriber.subscriptions.first.name.should == "The New York Times"
end
-
+
it "should be able to create a subscriber with two subscriptions (inline)" do
subscription_one = @obj.create_harpers_subscription
subscription_two = @obj.create_ny_times_subscription
-
+
subscriptions = [subscription_one, subscription_two]
-
+
subscriber = @obj.create_subscriber(:subscriptions => subscriptions)
-
+
subscriber.subscriptions.should == subscriptions
end
-
+
it "should be able to create a subscriber with two subscriptions, from the fixtures" do
subscriber = @obj.create_subscriber_with_two_subscriptions
subscriber.should have(2).subscriptions
end
end
-end