From 86970cafff488507123fe54f7841d449a27f5e4a Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 8 Oct 2009 22:27:19 -0400 Subject: [PATCH 01/24] Check for valid keys to attributes_for. Closes Github Issue #2 --- lib/fixture_replacement/attribute_builder.rb | 12 ++++++++++++ .../attributes_for_with_invalid_keys_spec.rb | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb diff --git a/lib/fixture_replacement/attribute_builder.rb b/lib/fixture_replacement/attribute_builder.rb index 7a60cea..7d812e2 100644 --- a/lib/fixture_replacement/attribute_builder.rb +++ b/lib/fixture_replacement/attribute_builder.rb @@ -19,6 +19,8 @@ def find_by_fixture_name(arg) end def initialize(fixture_name, options={}, &block) + check_valid_keys(options, [:from, :class]) + @fixture_name = fixture_name @attributes_proc = block || lambda {} @from = options[:from] @@ -44,6 +46,16 @@ def instantiate(hash_to_merge = {}, instance = active_record_class.new) private + class InvalidKeyError < StandardError; end + + def check_valid_keys(options_given, valid_keys) + options_given.each do |key, _| + unless valid_keys.include?(key) + raise InvalidKeyError, "#{key.inspect} is not a valid option to attributes_for. Valid keys are: #{valid_keys.inspect}" + end + end + end + def instantiate_parent_fixture(instance) derived_fixture.instantiate({}, instance) if derived_fixture? end diff --git a/spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb b/spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb new file mode 100644 index 0000000..b9e392c --- /dev/null +++ b/spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb @@ -0,0 +1,14 @@ +require File.dirname(__FILE__) + "/../../spec_helper" + +module FixtureReplacement + describe "keys passed to attributes for" do + it "should raise an invalid key error when an invalid key is passed" do + lambda { + use_module do + attributes_for :user, :class_name => "foo" + end + }.should raise_error(FixtureReplacement::AttributeBuilder::InvalidKeyError, + ":class_name is not a valid option to attributes_for. Valid keys are: [:from, :class]") + end + end +end \ No newline at end of file From 581b7fa723e20e07d1b3f564da5685138968f025 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 9 Oct 2009 00:48:25 -0400 Subject: [PATCH 02/24] Spacing --- spec/spec_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helpers.rb b/spec/spec_helpers.rb index ad33afc..1acaf11 100644 --- a/spec/spec_helpers.rb +++ b/spec/spec_helpers.rb @@ -8,7 +8,7 @@ def setup_database_connection ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:' ActiveRecord::Migration.verbose = false - ActiveRecord::Schema.define do + ActiveRecord::Schema.define do create_table :users, :force => true do |t| t.column :key, :string t.column :other_key, :string From 76ed00c559cb438152cbd25225477f8eb7ae9759 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 9 Oct 2009 00:48:57 -0400 Subject: [PATCH 03/24] Remove unnecessary spec helpers --- spec/spec_helper.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aa411cd..ff0c951 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,3 @@ - -require "rubygems" -require "spec" - require File.dirname(__FILE__) + "/spec_helpers" include SpecHelperFunctions setup_database_connection From 7d155dd2699511d48e2b232dc3fd79d4223cf3c4 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 9 Oct 2009 00:50:13 -0400 Subject: [PATCH 04/24] Remove unnecessary require active_support --- spec/spec_helpers.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helpers.rb b/spec/spec_helpers.rb index 1acaf11..ce68394 100644 --- a/spec/spec_helpers.rb +++ b/spec/spec_helpers.rb @@ -3,7 +3,6 @@ def setup_database_connection require 'rubygems' require 'sqlite3' require 'active_record' - require 'active_support' ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:' ActiveRecord::Migration.verbose = false From 880a5e9643423c54bc5216ad9fa65e3d14608e5a Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 9 Oct 2009 01:00:04 -0400 Subject: [PATCH 05/24] Allow symbols to be used in the fixture name, in the options hash passed to attributes_for. Closes Github Issue #7 --- lib/fixture_replacement/attribute_builder.rb | 6 ++++-- .../attribute_builder_spec.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/fixture_replacement/attribute_builder.rb b/lib/fixture_replacement/attribute_builder.rb index 7d812e2..7bb08d1 100644 --- a/lib/fixture_replacement/attribute_builder.rb +++ b/lib/fixture_replacement/attribute_builder.rb @@ -19,11 +19,13 @@ def find_by_fixture_name(arg) end def initialize(fixture_name, options={}, &block) + options.symbolize_keys! + check_valid_keys(options, [:from, :class]) - @fixture_name = fixture_name + @fixture_name = fixture_name.to_sym @attributes_proc = block || lambda {} - @from = options[:from] + @from = options[:from].to_sym if options.has_key?(:from) @class = options[:class] self.class.add_instance(self) diff --git a/spec/fixture_replacement/attribute_builder_spec.rb b/spec/fixture_replacement/attribute_builder_spec.rb index 71dac93..995e89c 100644 --- a/spec/fixture_replacement/attribute_builder_spec.rb +++ b/spec/fixture_replacement/attribute_builder_spec.rb @@ -82,5 +82,23 @@ module FixtureReplacement 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 + end end end From 0f79fa972fbe89c26c8a69cc2b2ce439299a6294 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 12 Oct 2009 21:36:14 -0400 Subject: [PATCH 06/24] Validate instances with FixtureReplacement.validate! Resolves Github #1 --- lib/fixture_replacement.rb | 4 +- lib/fixture_replacement/attribute_builder.rb | 18 +++ lib/fixture_replacement/class_methods.rb | 5 + .../attribute_builder_spec.rb | 60 +++++++++- spec/fixture_replacement/fixtures/classes.rb | 104 +++++++++++------- .../integration/validation_spec.rb | 54 +++++++++ spec/spec_helpers.rb | 28 ++++- 7 files changed, 229 insertions(+), 44 deletions(-) create mode 100644 spec/fixture_replacement/integration/validation_spec.rb diff --git a/lib/fixture_replacement.rb b/lib/fixture_replacement.rb index 3e75583..cd0e759 100644 --- a/lib/fixture_replacement.rb +++ b/lib/fixture_replacement.rb @@ -5,8 +5,10 @@ load "#{dir}/method_generator.rb" module FixtureReplacement + class InvalidInstance < StandardError; end + include FixtureReplacement::Version extend FixtureReplacement::ClassMethods end -FixtureReplacement.load_example_data +FixtureReplacement.load_example_data \ No newline at end of file diff --git a/lib/fixture_replacement/attribute_builder.rb b/lib/fixture_replacement/attribute_builder.rb index 7bb08d1..b8e8157 100644 --- a/lib/fixture_replacement/attribute_builder.rb +++ b/lib/fixture_replacement/attribute_builder.rb @@ -1,6 +1,14 @@ module FixtureReplacement class AttributeBuilder class << self + def validate_instances! + instances.each do |fixture| + fixture.validate! + end + + true + end + def instances @instances ||= [] end @@ -46,6 +54,16 @@ def instantiate(hash_to_merge = {}, instance = active_record_class.new) end end + def validate! + new_instance = instantiate + + unless new_instance.valid? + errors = "new_#{fixture_name} is not valid! - Errors: " + errors << new_instance.errors.map { |key, value| "[#{key}: #{value}]"}.join(", ") + raise InvalidInstance, errors + end + end + private class InvalidKeyError < StandardError; end diff --git a/lib/fixture_replacement/class_methods.rb b/lib/fixture_replacement/class_methods.rb index 3ca1821..08ef809 100644 --- a/lib/fixture_replacement/class_methods.rb +++ b/lib/fixture_replacement/class_methods.rb @@ -4,6 +4,10 @@ def attributes_for(fixture_name, options={}, &block) builder = AttributeBuilder.new(fixture_name, options, &block) MethodGenerator.new(builder, self).generate_methods end + + def validate! + AttributeBuilder.validate_instances! + end def random_string(length=10) chars = ("a".."z").to_a @@ -23,6 +27,7 @@ def rails_root end def reload! + AttributeBuilder.clear_out_instances! load File.expand_path(File.dirname(__FILE__) + "/../fixture_replacement.rb") end diff --git a/spec/fixture_replacement/attribute_builder_spec.rb b/spec/fixture_replacement/attribute_builder_spec.rb index 995e89c..240018a 100644 --- a/spec/fixture_replacement/attribute_builder_spec.rb +++ b/spec/fixture_replacement/attribute_builder_spec.rb @@ -1,7 +1,11 @@ require File.dirname(__FILE__) + "/../spec_helper" module FixtureReplacement - describe AttributeBuilder do + describe AttributeBuilder do + before do + AttributeBuilder.clear_out_instances! + end + it "should add the instance to the global attributes" do a = AttributeBuilder.new(:foo) AttributeBuilder.instances.should == [a] @@ -100,5 +104,59 @@ module FixtureReplacement builder = AttributeBuilder.new("admin") builder.fixture_name.should == :admin end + + describe "validating all instances" do + it "should return true if there are no instances" do + AttributeBuilder.validate_instances!.should be_true + end + + it "should raise an error if an instance is not valid" do + AttributeBuilder.new(:validate_name) + + lambda { + AttributeBuilder.validate_instances! + }.should raise_error + end + + it "should not raise an error if there is only one instance, and it is valid" do + AttributeBuilder.new(:event) + + lambda { + AttributeBuilder.validate_instances! + }.should_not raise_error + end + + it "should raise an error, giving the fixture name, and the error" do + AttributeBuilder.new(:validate_name) + + lambda { + AttributeBuilder.validate_instances! + }.should raise_error(FixtureReplacement::InvalidInstance, "new_validate_name is not valid! - Errors: [name: can't be blank]") + end + + it "should use the correct name" do + AttributeBuilder.new(:validate_name_two) + + lambda { + AttributeBuilder.validate_instances! + }.should raise_error(FixtureReplacement::InvalidInstance, "new_validate_name_two is not valid! - Errors: [name: can't be blank]") + end + + it "should use the correct errors" do + AttributeBuilder.new(:address_with_valid_city) + + lambda { + AttributeBuilder.validate_instances! + }.should raise_error(FixtureReplacement::InvalidInstance, "new_address_with_valid_city is not valid! - Errors: [city: can't be blank]") + end + + it "should use multiple errors on a single model" do + AttributeBuilder.new(:address_with_valid_city_and_state) + + lambda { + AttributeBuilder.validate_instances! + }.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 diff --git a/spec/fixture_replacement/fixtures/classes.rb b/spec/fixture_replacement/fixtures/classes.rb index f07e1e8..41bb100 100644 --- a/spec/fixture_replacement/fixtures/classes.rb +++ b/spec/fixture_replacement/fixtures/classes.rb @@ -1,56 +1,78 @@ -class User < ActiveRecord::Base - belongs_to :gender -end +unless defined?(User) + class User < ActiveRecord::Base + belongs_to :gender + end -class Member < ActiveRecord::Base; end + class Member < ActiveRecord::Base; end -class Post < ActiveRecord::Base - has_many :comments -end + class Post < ActiveRecord::Base + has_many :comments + end -class Comment < ActiveRecord::Base - belongs_to :post -end + class Comment < ActiveRecord::Base + belongs_to :post + end -class Player < ActiveRecord::Base -end + class Player < ActiveRecord::Base + end -class Alien < ActiveRecord::Base - belongs_to :gender -end + class Alien < ActiveRecord::Base + belongs_to :gender + end -class Admin < ActiveRecord::Base - attr_protected :admin_status -end + class Admin < ActiveRecord::Base + attr_protected :admin_status + end -class Gender < ActiveRecord::Base; end -class Actress < ActiveRecord::Base; end + class Gender < ActiveRecord::Base; end + class Actress < ActiveRecord::Base; end -class Item < ActiveRecord::Base - belongs_to :category -end + class Item < ActiveRecord::Base + belongs_to :category + end -class Writing < Item; end + class Writing < Item; end -class Category < ActiveRecord::Base - has_many :items -end + class Category < ActiveRecord::Base + has_many :items + end -class Subscriber < ActiveRecord::Base - has_and_belongs_to_many :subscriptions -end + class Subscriber < ActiveRecord::Base + has_and_belongs_to_many :subscriptions + end -class Subscription < ActiveRecord::Base - has_and_belongs_to_many :subscribers -end + class Subscription < ActiveRecord::Base + has_and_belongs_to_many :subscribers + end -class Event < ActiveRecord::Base - has_one :schedule -end + class Event < ActiveRecord::Base + has_one :schedule + end -class Schedule < ActiveRecord::Base - belongs_to :event -end + class Schedule < ActiveRecord::Base + belongs_to :event + end -class Foo; end -class Bar; end \ No newline at end of file + class Foo; end + class Bar; end + + class NoValidation < ActiveRecord::Base + end + + class ValidateName < ActiveRecord::Base + validates_presence_of :name + end + + class ValidateNameTwo < ActiveRecord::Base + validates_presence_of :name + end + + class AddressWithValidCity < ActiveRecord::Base + validates_presence_of :city + end + + class AddressWithValidCityAndState < ActiveRecord::Base + validates_presence_of :city + validates_presence_of :state + end +end \ No newline at end of file diff --git a/spec/fixture_replacement/integration/validation_spec.rb b/spec/fixture_replacement/integration/validation_spec.rb new file mode 100644 index 0000000..04c3686 --- /dev/null +++ b/spec/fixture_replacement/integration/validation_spec.rb @@ -0,0 +1,54 @@ +require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") + +module FixtureReplacement + describe "validations" do + it "should not raise with a record that has no validations" do + fr = mock_fr_module do + attributes_for :no_validation do + end + end + + lambda { + fr.validate! + }.should_not raise_error + end + + it "should raise an error when the record is not valid" do + fr = mock_fr_module do + attributes_for :validate_name + end + + lambda { + fr.validate! + }.should raise_error + end + + it "should not raise if the record is valid" do + fr = mock_fr_module do + attributes_for :validate_name do |n| + n.name = "Scott" + end + end + + lambda { + fr.validate! + }.should_not raise_error + end + + it "should not raise if first loaded with an invalid record, and later a valid one after reloading" do + fr = mock_fr_module do + attributes_for :validate_name + end + + fr.reload! + + fr.attributes_for :validate_name do |n| + n.name = "Scott" + end + + lambda { + fr.validate! + }.should_not raise_error + end + end +end diff --git a/spec/spec_helpers.rb b/spec/spec_helpers.rb index ce68394..c6dd4a0 100644 --- a/spec/spec_helpers.rb +++ b/spec/spec_helpers.rb @@ -76,12 +76,38 @@ def setup_database_connection t.integer :post_id t.timestamps end + + create_table :no_validations do |t| + t.timestamps + end + + create_table :validate_names do |t| + t.string :name + end + + create_table :validate_name_twos do |t| + t.string :name + end + + create_table :address_with_valid_cities do |t| + t.string :city + end + + create_table :address_with_valid_city_and_states do |t| + t.string :city + t.string :state + end end - def use_module(&block) + def mock_fr_module(&block) mod = Module.new mod.extend(FixtureReplacement::ClassMethods) mod.instance_eval(&block) + mod + end + + def use_module(&block) + mod = mock_fr_module(&block) obj = Object.new obj.extend mod From 28c3e4b2f93d9acababa2330ad376a30fc8bbc6f Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 12 Oct 2009 21:36:49 -0400 Subject: [PATCH 07/24] Update the CHANGELOG --- CHANGELOG.rdoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index a89cc31..e8e8f02 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,7 @@ +== HEAD + +- validate instances with FixtureReplacement.validate! + == 3.0.0 - Better Support for Reloading (call FR.reload! after calling reload! in the console or in your spec helper) From c7a72fded6124184a0dcb6655850025db86ea7bf Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 12 Oct 2009 21:37:10 -0400 Subject: [PATCH 08/24] Thank Pat Nakajima --- contributions.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributions.rdoc b/contributions.rdoc index 3d95793..8ea9268 100644 --- a/contributions.rdoc +++ b/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. \ No newline at end of file + of new_* methods. validation of new instances. \ No newline at end of file From ec674432387945530df03c8a07cf0da523caa0df Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Mon, 12 Oct 2009 21:41:04 -0400 Subject: [PATCH 09/24] Add Validation documentation to README --- README.rdoc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.rdoc b/README.rdoc index e723097..f15fcab 100644 --- a/README.rdoc +++ b/README.rdoc @@ -110,6 +110,26 @@ 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: + +==== spec_helper.rb: + + Spec::Runner.configuration do |config| + config.include FixtureReplacement + end + + FixtureReplacement.validate! + +==== test_helper.rb + + class Test::Unit::TestCase + include FixtureReplacement + end + + FixtureReplacement.validate! + === Using FixtureReplacement within script/console $ ./script/console From fbf8fa42aa0d4034bb9bcba49ff6fd1a28e54ec6 Mon Sep 17 00:00:00 2001 From: Wincent Colaiuta Date: Fri, 20 Nov 2009 21:52:16 +0100 Subject: [PATCH 10/24] Fix typo in README (Resolves Github #9) FixtureReplacement generates methods like "valid_user_attributes", not "valid_user". Signed-off-by: Wincent Colaiuta --- README.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index f15fcab..c63ecf3 100644 --- a/README.rdoc +++ b/README.rdoc @@ -83,7 +83,7 @@ Based on the above definition FixtureReplacement makes the following methods ava - random_string: generates a random string as shown above - new_user: equivalent to User.new with the attributes for the user. - create_user: equivalent to User.create! with the user's attributes. -- valid_user: returns a hash of the user's attributes including associations, specified in db/example_data.rb. +- valid_user_attributes: returns a hash of the user's attributes including associations, specified in db/example_data.rb. === Overriding attributes From 9d3d29d39850787559e0b52bae99bf6f2bfe2bc8 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 02:36:16 -0500 Subject: [PATCH 11/24] Split up rake tasks into separate files --- Rakefile | 126 ++----------------------------------- rake_tasks/code_quality.rb | 37 +++++++++++ rake_tasks/docs.rb | 59 +++++++++++++++++ rake_tasks/specs.rb | 7 +++ rake_tasks/tests.rb | 7 +++ rake_tasks/website.rb | 11 ++++ 6 files changed, 125 insertions(+), 122 deletions(-) create mode 100644 rake_tasks/code_quality.rb create mode 100644 rake_tasks/docs.rb create mode 100644 rake_tasks/specs.rb create mode 100644 rake_tasks/tests.rb create mode 100644 rake_tasks/website.rb diff --git a/Rakefile b/Rakefile index 85cad3c..551b3de 100644 --- a/Rakefile +++ b/Rakefile @@ -1,126 +1,8 @@ require 'rake' -require 'rake/testtask' -require 'hanna/rdoctask' -require 'spec/rake/spectask' -require 'spec/rake/verify_rcov' -require 'rake/contrib/rubyforgepublisher' -Rake::TestTask.new do |t| - t.libs << "test" - t.test_files = FileList['test/**/*test*.rb'] - t.verbose = true +Dir.glob("rake_tasks/**/*.rb").each do |file| + require file end -desc 'Default: run unit tests.' -task :default => [:spec, :test] - -# Create specs + Rake Task - -def doc_directory - "doc" -end - -desc 'Generate documentation for the fixture_replacement plugin.' -Rake::RDocTask.new(:rdoc_without_analytics) do |rdoc| - rdoc.rdoc_dir = doc_directory - rdoc.title = 'FixtureReplacement' - rdoc.options << '--line-numbers' << '--inline-source' - - rdoc.options << '--webcvs=http://github.com/smtlaissezfaire/fixturereplacement/tree/master/' - - [ - "README.rdoc", - "CHANGELOG.rdoc", - "GPL_LICENSE", - "MIT_LICENSE", - "contributions.rdoc", - "philosophy_and_bugs.rdoc", - "lib/**/*.rb" - ].each do |file| - rdoc.rdoc_files.include(file) - end -end - -task :rdoc => [:rdoc_without_analytics] do - google_analytics = File.read(File.dirname(__FILE__) + "/etc/google_analytics") - rdoc_index = File.dirname(__FILE__) + "/#{doc_directory}/index.html" - - contents = File.read(rdoc_index) - contents.gsub!("", "#{google_analytics}\n") - - File.open(rdoc_index, "r+") do |file| - file.write(contents) - end -end - -task :rerdoc => [:clobber_rdoc, :rdoc] -task :clobber_rdoc => [:clobber_rdoc_without_analytics] - -desc 'Run the specs' -Spec::Rake::SpecTask.new do |t| - t.warning = false - t.spec_opts = ["--color"] -end - -desc 'Publish the website, building the docs first' -task :publish_website => [:build_docs] do - publisher = Rake::SshDirPublisher.new( - "smtlaissezfaire@rubyforge.org", - "/var/www/gforge-projects/replacefixtures/", - "doc" - ) - publisher.upload -end - -def create_doc_directory - unless File.exists?(doc_directory) - `mkdir doc` - end -end - -task :create_doc_directory do - create_doc_directory -end - -desc "Create the html specdoc" -Spec::Rake::SpecTask.new(:specdoc => :create_doc_directory) do |t| - t.spec_opts = ["--format", "html:doc/specdoc.html"] -end - -desc 'Create the specdoc + rdoc' -task :build_docs => [:rerdoc, :specdoc, :rcov, :flog_to_disk] - -desc "Run all examples with RCov" -Spec::Rake::SpecTask.new(:rcov) do |t| - t.rcov = true - t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems'] - t.rcov_dir = "doc/rcov" -end - -desc "Feel the pain of my code, and submit a refactoring patch" -task :flog do - puts %x(find lib | grep ".rb$" | xargs flog) -end - -task :flog_to_disk => :create_doc_directory do - puts "Flogging..." - %x(find lib | grep ".rb$" | xargs flog > doc/flog.txt) - puts "Done Flogging...\n" -end - -def sloc - `sloccount #{File.dirname(__FILE__)}/lib` -end - -desc "Output sloccount report. You'll need sloccount installed." -task :sloc do - puts "Counting lines of code" - puts sloc -end - -desc "Write sloccount report" -task :output_sloc => :create_doc_directory do - File.open(File.dirname(__FILE__) + "/doc/lines_of_code.txt", "w") do |f| - f << sloc - end -end \ No newline at end of file +desc 'Default: run unit tests (specs + tests).' +task :default => [:spec, :test] \ No newline at end of file diff --git a/rake_tasks/code_quality.rb b/rake_tasks/code_quality.rb new file mode 100644 index 0000000..bc69940 --- /dev/null +++ b/rake_tasks/code_quality.rb @@ -0,0 +1,37 @@ +require 'spec/rake/spectask' +require 'spec/rake/verify_rcov' + +desc "Run all examples with RCov" +Spec::Rake::SpecTask.new(:rcov) do |t| + t.rcov = true + t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems'] + t.rcov_dir = "doc/rcov" +end + +desc "Feel the pain of my code, and submit a refactoring patch" +task :flog do + puts %x(find lib | grep ".rb$" | xargs flog) +end + +task :flog_to_disk => :create_doc_directory do + puts "Flogging..." + %x(find lib | grep ".rb$" | xargs flog > doc/flog.txt) + puts "Done Flogging...\n" +end + +def sloc + `sloccount #{File.dirname(__FILE__)}/lib` +end + +desc "Output sloccount report. You'll need sloccount installed." +task :sloc do + puts "Counting lines of code" + puts sloc +end + +desc "Write sloccount report" +task :output_sloc => :create_doc_directory do + File.open(File.dirname(__FILE__) + "/doc/lines_of_code.txt", "w") do |f| + f << sloc + end +end \ No newline at end of file diff --git a/rake_tasks/docs.rb b/rake_tasks/docs.rb new file mode 100644 index 0000000..6458d3b --- /dev/null +++ b/rake_tasks/docs.rb @@ -0,0 +1,59 @@ +require 'hanna/rdoctask' + +def doc_directory + "doc" +end + +desc 'Generate documentation for the fixture_replacement plugin.' +Rake::RDocTask.new(:rdoc_without_analytics) do |rdoc| + rdoc.rdoc_dir = doc_directory + rdoc.title = 'FixtureReplacement' + rdoc.options << '--line-numbers' << '--inline-source' + + rdoc.options << '--webcvs=http://github.com/smtlaissezfaire/fixturereplacement/tree/master/' + + [ + "README.rdoc", + "CHANGELOG.rdoc", + "GPL_LICENSE", + "MIT_LICENSE", + "contributions.rdoc", + "philosophy_and_bugs.rdoc", + "lib/**/*.rb" + ].each do |file| + rdoc.rdoc_files.include(file) + end +end + +task :rdoc => [:rdoc_without_analytics] do + google_analytics = File.read(File.dirname(__FILE__) + "/etc/google_analytics") + rdoc_index = File.dirname(__FILE__) + "/#{doc_directory}/index.html" + + contents = File.read(rdoc_index) + contents.gsub!("", "#{google_analytics}\n") + + File.open(rdoc_index, "r+") do |file| + file.write(contents) + end +end + +task :rerdoc => [:clobber_rdoc, :rdoc] +task :clobber_rdoc => [:clobber_rdoc_without_analytics] + +def create_doc_directory + unless File.exists?(doc_directory) + `mkdir doc` + end +end + +task :create_doc_directory do + create_doc_directory +end + +desc "Create the html specdoc" +Spec::Rake::SpecTask.new(:specdoc => :create_doc_directory) do |t| + t.spec_opts = ["--format", "html:doc/specdoc.html"] +end + +desc 'Create the specdoc + rdoc' +task :build_docs => [:rerdoc, :specdoc, :rcov, :flog_to_disk] \ No newline at end of file diff --git a/rake_tasks/specs.rb b/rake_tasks/specs.rb new file mode 100644 index 0000000..460da84 --- /dev/null +++ b/rake_tasks/specs.rb @@ -0,0 +1,7 @@ +require 'spec/rake/spectask' + +desc 'Run the specs' +Spec::Rake::SpecTask.new do |t| + t.warning = false + t.spec_opts = ["--color"] +end diff --git a/rake_tasks/tests.rb b/rake_tasks/tests.rb new file mode 100644 index 0000000..a7ea472 --- /dev/null +++ b/rake_tasks/tests.rb @@ -0,0 +1,7 @@ +require 'rake/testtask' + +Rake::TestTask.new do |t| + t.libs << "test" + t.test_files = FileList['test/**/*test*.rb'] + t.verbose = true +end diff --git a/rake_tasks/website.rb b/rake_tasks/website.rb new file mode 100644 index 0000000..c454d17 --- /dev/null +++ b/rake_tasks/website.rb @@ -0,0 +1,11 @@ +require 'rake/contrib/rubyforgepublisher' + +desc 'Publish the website, building the docs first' +task :publish_website => [:build_docs] do + publisher = Rake::SshDirPublisher.new( + "smtlaissezfaire@rubyforge.org", + "/var/www/gforge-projects/replacefixtures/", + "doc" + ) + publisher.upload +end From b271b43b588d77e9d907e49bae3199797382b573 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:00:20 -0500 Subject: [PATCH 12/24] Add jewler rake task. Automatically generate the version file every time we run rake --- rake_tasks/gem.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rake_tasks/gem.rb diff --git a/rake_tasks/gem.rb b/rake_tasks/gem.rb new file mode 100644 index 0000000..1997f2b --- /dev/null +++ b/rake_tasks/gem.rb @@ -0,0 +1,27 @@ +require File.expand_path(File.dirname(__FILE__) + "/../lib/fixture_replacement") + +begin + require 'jeweler' + + Jeweler::Tasks.new do |gemspec| + File.open(File.expand_path(File.dirname(__FILE__) + "/../VERSION"), "w") do |f| + f << FixtureReplacement::Version::VERSION + end + + gemspec.name = "fixture_replacement" + gemspec.summary = "The original fixture replacement solution for rails" + gemspec.email = "scott@railsnewbie.com" + gemspec.homepage = "http://replacefixtures.rubyforge.org" + gemspec.authors = ["Scott Taylor"] + gemspec.description = <<-DESC +FixtureReplacement is a Rails 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. + DESC + end + + Jeweler::GemcutterTasks.new +rescue LoadError + puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com" +end \ No newline at end of file From 0bb137f739c3edaf6d9e8f92c8436ef331213579 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:00:53 -0500 Subject: [PATCH 13/24] Add the version file --- VERSION | 1 + 1 file changed, 1 insertion(+) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..56fea8a --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +3.0.0 \ No newline at end of file From 10cb11818da972d2bbef44c11fa32aadb63976ab Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:01:46 -0500 Subject: [PATCH 14/24] Ignore the pkg directory --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 325ab0d..3103921 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -doc \ No newline at end of file +doc +pkg \ No newline at end of file From 51724320a203e3eac6cc8b0eb59eb0c5f453b092 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:09:41 -0500 Subject: [PATCH 15/24] Add FixtureReplacement's lib/ directory to the load path --- lib/fixture_replacement.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/fixture_replacement.rb b/lib/fixture_replacement.rb index cd0e759..e31562f 100644 --- a/lib/fixture_replacement.rb +++ b/lib/fixture_replacement.rb @@ -1,8 +1,8 @@ -dir = File.dirname(__FILE__) + "/fixture_replacement" -load "#{dir}/version.rb" -load "#{dir}/class_methods.rb" -load "#{dir}/attribute_builder.rb" -load "#{dir}/method_generator.rb" +$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), ".")) +load "fixture_replacement/version.rb" +load "fixture_replacement/class_methods.rb" +load "fixture_replacement/attribute_builder.rb" +load "fixture_replacement/method_generator.rb" module FixtureReplacement class InvalidInstance < StandardError; end From 747aeb28d762d36ad86c3f3ef9cf6467951400c9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:10:47 -0500 Subject: [PATCH 16/24] load "fr.rb" when loading "fixture_replacement" --- lib/fixture_replacement.rb | 2 ++ spec/spec_helper.rb | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/fixture_replacement.rb b/lib/fixture_replacement.rb index e31562f..b7d7868 100644 --- a/lib/fixture_replacement.rb +++ b/lib/fixture_replacement.rb @@ -11,4 +11,6 @@ class InvalidInstance < StandardError; end extend FixtureReplacement::ClassMethods end +load "fr.rb" + FixtureReplacement.load_example_data \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ff0c951..e73f399 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,14 +3,13 @@ setup_database_connection require File.dirname(__FILE__) + "/../lib/fixture_replacement" -require File.dirname(__FILE__) + "/../lib/fr" require File.dirname(__FILE__) + "/fixture_replacement/fixtures/classes" Spec::Runner.configure do |config| config.prepend_before(:each) do FixtureReplacement::AttributeBuilder.clear_out_instances! end - + config.prepend_after(:each) do FixtureReplacement::AttributeBuilder.clear_out_instances! end From 1fba1e9dbd7769fe6e442f796e271eeaba49cd26 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:11:45 -0500 Subject: [PATCH 17/24] Remove unnecessary whitespace from the project --- CHANGELOG.rdoc | 8 +- README.rdoc | 46 ++--- Rakefile | 2 +- TODO.rdoc | 2 +- VERSION | 2 +- contributions.rdoc | 2 +- etc/bug_reports/2007_09_28_linoj.txt | 2 +- etc/google_analytics | 2 +- ..._14_default_model_name_with_arguments.diff | 2 +- .../2007_10_14_active_record_specs.diff | 158 +++++++++--------- .../2007_10_14_protected_attributes.diff | 4 +- etc/patches/2007_10_14_send_patch.diff | 20 +-- ...2007_10_14_spelling_error_in_comments.diff | 2 +- ..._10_17_protected_attributes_second_go.diff | 68 ++++---- etc/patches/2007_10_18_README.diff | 62 +++---- etc/patches/2007_10_19_silence_migration.diff | 6 +- ...07_10_25_changed_classify_to_camelize.diff | 16 +- ...hould_not_reload_environment_or_boot.patch | 2 +- ...string_random_refactor_and_extension.patch | 16 +- ...ing_random_refactor_and_extension_v2.patch | 16 +- lib/fixture_replacement.rb | 2 +- lib/fixture_replacement/attribute_builder.rb | 32 ++-- lib/fixture_replacement/class_methods.rb | 6 +- lib/fixture_replacement/method_generator.rb | 6 +- lib/fixture_replacement/version.rb | 2 +- philosophy_and_bugs.rdoc | 6 +- rake_tasks/code_quality.rb | 2 +- rake_tasks/docs.rb | 2 +- rake_tasks/gem.rb | 2 +- .../attribute_builder_spec.rb | 42 ++--- .../fixture_replacement_spec.rb | 4 +- spec/fixture_replacement/fixtures/classes.rb | 2 +- spec/fixture_replacement/fr_spec.rb | 2 +- .../attr_protected_attributes_spec.rb | 22 +-- .../attributes_for_with_invalid_keys_spec.rb | 2 +- .../attributes_from_spec_without_block.rb | 18 +- .../integration/create_method_spec.rb | 24 +-- .../integration/cyclic_dependency_spec.rb | 12 +- .../integration/default_warnings_spec.rb | 12 +- .../integration/extend_spec.rb | 10 +- .../has_and_belongs_to_many_spec.rb | 18 +- .../integration/new_method_spec.rb | 38 ++--- .../integration/private_methods_spec.rb | 14 +- .../integration/public_methods_spec.rb | 6 +- .../integration/valid_attributes_spec.rb | 16 +- .../2008_01_21_random_string_with_sti_spec.rb | 30 ++-- spec/spec_helpers.rb | 32 ++-- test/unit/user_test.rb | 22 +-- 48 files changed, 412 insertions(+), 412 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index e8e8f02..7d7d696 100644 --- a/CHANGELOG.rdoc +++ b/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 => # - + - 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 diff --git a/README.rdoc b/README.rdoc index c63ecf3..1fd49db 100644 --- a/README.rdoc +++ b/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 test/test_helper.rb file: === Defining default attributes -At the heart of FixtureReplacement is the db/example_data.rb file where you +At the heart of FixtureReplacement is the db/example_data.rb 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 password is generated and then used for both the :password and +- you can perform arbitrary set-up and execute any Ruby code prior to returning the hash + (as shown here where a password is generated and then used for both the :password and :password_confirmation attributes) -- a new_modelname method is automatically provided that allows you to set up dependent +- a new_modelname method is automatically provided that allows you to set up dependent model objects (in this case an instance of the Bar 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 script/console - $ ./script/console + $ ./script/console Loading development environment >> include FR => Object diff --git a/Rakefile b/Rakefile index 551b3de..786166f 100644 --- a/Rakefile +++ b/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] \ No newline at end of file +task :default => [:spec, :test] diff --git a/TODO.rdoc b/TODO.rdoc index 9bbe620..223c5b3 100644 --- a/TODO.rdoc +++ b/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) \ No newline at end of file +- Remove TODOs from Rubyforge tracker (http://rubyforge.org/tracker/?group_id=4556) diff --git a/VERSION b/VERSION index 56fea8a..4a36342 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0 \ No newline at end of file +3.0.0 diff --git a/contributions.rdoc b/contributions.rdoc index 8ea9268..8237b2b 100644 --- a/contributions.rdoc +++ b/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. \ No newline at end of file + of new_* methods. validation of new instances. diff --git a/etc/bug_reports/2007_09_28_linoj.txt b/etc/bug_reports/2007_09_28_linoj.txt index 426850d..2bbdbc1 100644 --- a/etc/bug_reports/2007_09_28_linoj.txt +++ b/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 diff --git a/etc/google_analytics b/etc/google_analytics index b4efae9..cff5c93 100644 --- a/etc/google_analytics +++ b/etc/google_analytics @@ -3,4 +3,4 @@ \ No newline at end of file + diff --git a/etc/patches/2007_09_14_default_model_name_with_arguments.diff b/etc/patches/2007_09_14_default_model_name_with_arguments.diff index 66a5dfa..7216f07 100644 --- a/etc/patches/2007_09_14_default_model_name_with_arguments.diff +++ b/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| diff --git a/etc/patches/2007_10_14_active_record_specs.diff b/etc/patches/2007_10_14_active_record_specs.diff index c856086..7a9211a 100644 --- a/etc/patches/2007_10_14_active_record_specs.diff +++ b/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 - + diff --git a/etc/patches/2007_10_14_protected_attributes.diff b/etc/patches/2007_10_14_protected_attributes.diff index efccae9..546ad27 100644 --- a/etc/patches/2007_10_14_protected_attributes.diff +++ b/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 @@ diff --git a/etc/patches/2007_10_14_send_patch.diff b/etc/patches/2007_10_14_send_patch.diff index e1d8b5b..e201d7e 100644 --- a/etc/patches/2007_10_14_send_patch.diff +++ b/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 - + diff --git a/etc/patches/2007_10_14_spelling_error_in_comments.diff b/etc/patches/2007_10_14_spelling_error_in_comments.diff index fb50b55..2072da2 100644 --- a/etc/patches/2007_10_14_spelling_error_in_comments.diff +++ b/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, diff --git a/etc/patches/2007_10_17_protected_attributes_second_go.diff b/etc/patches/2007_10_17_protected_attributes_second_go.diff index 61448b8..8cd24fc 100644 --- a/etc/patches/2007_10_17_protected_attributes_second_go.diff +++ b/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 - - + + diff --git a/etc/patches/2007_10_18_README.diff b/etc/patches/2007_10_18_README.diff index a905acf..db333b1 100644 --- a/etc/patches/2007_10_18_README.diff +++ b/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 db/example_data.rb file where you define the default attributes for each of your test models. This example shows a user_attributes method that returns the attributes for an instance of the User 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 db/example_data.rb: - + ruby script/generate fixture_replacement - + +=== Using from within script/console - + -=== Running the Specs/Tests for FixtureReplacement + % script/console + >> include FixtureReplacement - + +=== Using from with RSpec + +Add the following to your spec/spec_helper.rb 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 rake - + % 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 lib/fixture_replacement.rb diff --git a/etc/patches/2007_10_19_silence_migration.diff b/etc/patches/2007_10_19_silence_migration.diff index 9aae4fe..eed2475 100644 --- a/etc/patches/2007_10_19_silence_migration.diff +++ b/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| diff --git a/etc/patches/2007_10_25_changed_classify_to_camelize.diff b/etc/patches/2007_10_25_changed_classify_to_camelize.diff index 8b1765f..c9a58ba 100644 --- a/etc/patches/2007_10_25_changed_classify_to_camelize.diff +++ b/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 diff --git a/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch b/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch index f5e56d2..9d47658 100644 --- a/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch +++ b/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'], diff --git a/etc/patches/2007_11_20_string_random_refactor_and_extension.patch b/etc/patches/2007_11_20_string_random_refactor_and_extension.patch index 2e7503e..01028e4 100644 --- a/etc/patches/2007_11_20_string_random_refactor_and_extension.patch +++ b/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 diff --git a/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch b/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch index b60a4d8..35a5834 100644 --- a/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch +++ b/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 diff --git a/lib/fixture_replacement.rb b/lib/fixture_replacement.rb index b7d7868..30aa5f2 100644 --- a/lib/fixture_replacement.rb +++ b/lib/fixture_replacement.rb @@ -13,4 +13,4 @@ class InvalidInstance < StandardError; end load "fr.rb" -FixtureReplacement.load_example_data \ No newline at end of file +FixtureReplacement.load_example_data diff --git a/lib/fixture_replacement/attribute_builder.rb b/lib/fixture_replacement/attribute_builder.rb index b8e8157..e3b34de 100644 --- a/lib/fixture_replacement/attribute_builder.rb +++ b/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 \ No newline at end of file +end diff --git a/lib/fixture_replacement/class_methods.rb b/lib/fixture_replacement/class_methods.rb index 08ef809..465eaf6 100644 --- a/lib/fixture_replacement/class_methods.rb +++ b/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 # diff --git a/lib/fixture_replacement/method_generator.rb b/lib/fixture_replacement/method_generator.rb index 46259c0..c6d76ee 100644 --- a/lib/fixture_replacement/method_generator.rb +++ b/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 diff --git a/lib/fixture_replacement/version.rb b/lib/fixture_replacement/version.rb index a9cdb54..99834b5 100644 --- a/lib/fixture_replacement/version.rb +++ b/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 diff --git a/philosophy_and_bugs.rdoc b/philosophy_and_bugs.rdoc index db0afaf..9724cde 100644 --- a/philosophy_and_bugs.rdoc +++ b/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. \ No newline at end of file +If you have other ideas for speeding up your test suite, I'm all ears. diff --git a/rake_tasks/code_quality.rb b/rake_tasks/code_quality.rb index bc69940..e846dd4 100644 --- a/rake_tasks/code_quality.rb +++ b/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 \ No newline at end of file +end diff --git a/rake_tasks/docs.rb b/rake_tasks/docs.rb index 6458d3b..f178146 100644 --- a/rake_tasks/docs.rb +++ b/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] \ No newline at end of file +task :build_docs => [:rerdoc, :specdoc, :rcov, :flog_to_disk] diff --git a/rake_tasks/gem.rb b/rake_tasks/gem.rb index 1997f2b..0f5e2e9 100644 --- a/rake_tasks/gem.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/attribute_builder_spec.rb b/spec/fixture_replacement/attribute_builder_spec.rb index 240018a..cb2672d 100644 --- a/spec/fixture_replacement/attribute_builder_spec.rb +++ b/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 diff --git a/spec/fixture_replacement/fixture_replacement_spec.rb b/spec/fixture_replacement/fixture_replacement_spec.rb index 1e517f3..fca9f32 100644 --- a/spec/fixture_replacement/fixture_replacement_spec.rb +++ b/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) diff --git a/spec/fixture_replacement/fixtures/classes.rb b/spec/fixture_replacement/fixtures/classes.rb index 41bb100..9873ad2 100644 --- a/spec/fixture_replacement/fixtures/classes.rb +++ b/spec/fixture_replacement/fixtures/classes.rb @@ -75,4 +75,4 @@ class AddressWithValidCityAndState < ActiveRecord::Base validates_presence_of :city validates_presence_of :state end -end \ No newline at end of file +end diff --git a/spec/fixture_replacement/fr_spec.rb b/spec/fixture_replacement/fr_spec.rb index ee49cc3..1f74a09 100644 --- a/spec/fixture_replacement/fr_spec.rb +++ b/spec/fixture_replacement/fr_spec.rb @@ -4,4 +4,4 @@ it "should alias FixtureReplacement" do FR.should equal(FixtureReplacement) end -end \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/attr_protected_attributes_spec.rb b/spec/fixture_replacement/integration/attr_protected_attributes_spec.rb index 9a8e256..3aa5d09 100644 --- a/spec/fixture_replacement/integration/attr_protected_attributes_spec.rb +++ b/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 \ No newline at end of file + end + end +end diff --git a/spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb b/spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb index b9e392c..e47709a 100644 --- a/spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/attributes_from_spec_without_block.rb b/spec/fixture_replacement/integration/attributes_from_spec_without_block.rb index e561809..e2ef2d9 100644 --- a/spec/fixture_replacement/integration/attributes_from_spec_without_block.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/create_method_spec.rb b/spec/fixture_replacement/integration/create_method_spec.rb index 6009302..0d8e860 100644 --- a/spec/fixture_replacement/integration/create_method_spec.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/cyclic_dependency_spec.rb b/spec/fixture_replacement/integration/cyclic_dependency_spec.rb index 5ac8b0d..2dc6538 100644 --- a/spec/fixture_replacement/integration/cyclic_dependency_spec.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/default_warnings_spec.rb b/spec/fixture_replacement/integration/default_warnings_spec.rb index 82fdf00..c7e8280 100644 --- a/spec/fixture_replacement/integration/default_warnings_spec.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/extend_spec.rb b/spec/fixture_replacement/integration/extend_spec.rb index 22f303f..4823f80 100644 --- a/spec/fixture_replacement/integration/extend_spec.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb b/spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb index 63c0e98..3123d9d 100644 --- a/spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb +++ b/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 \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/new_method_spec.rb b/spec/fixture_replacement/integration/new_method_spec.rb index be6f7f5..72f806a 100644 --- a/spec/fixture_replacement/integration/new_method_spec.rb +++ b/spec/fixture_replacement/integration/new_method_spec.rb @@ -6,91 +6,91 @@ module FixtureReplacement obj = use_module do attributes_for :user end - + obj.new_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.new_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.new_admin.should be_a_kind_of(Admin) end - + it "should return a new object with the keys given in user_attributes" do obj = use_module do attributes_for :user do |u| u.key = "val" end end - + obj.new_user.key.should == "val" end - + it "should over-write the User's hash with any hash given to new_user" do obj = use_module do attributes_for :user do |u| u.key = "val" end end - + obj.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 obj = use_module do attributes_for :user do |u| u.key = "val" end end - + user = obj.new_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.new_user.should be_a_new_record end - + it "should be able to be saved to the database" do obj = use_module do attributes_for :user do |u| u.key = "val" end end - + lambda { obj.new_user.save! }.should_not raise_error end - + it "should yield the object inside the block" do obj = nil - + mod = use_module do attributes_for :user do |u| obj = u end end - + mod.new_user # trigger the block obj.should be_a_kind_of(User) end end -end \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/private_methods_spec.rb b/spec/fixture_replacement/integration/private_methods_spec.rb index 723a322..130487c 100644 --- a/spec/fixture_replacement/integration/private_methods_spec.rb +++ b/spec/fixture_replacement/integration/private_methods_spec.rb @@ -7,37 +7,37 @@ module FixtureReplacement attributes_for :user_with_a_public_method, :class => User do |u| u.key = a_public_method end - + def a_public_method :public end end end - + it "should be able to call it" do user = @obj.new_user_with_a_public_method user.key.should == :public end end - + describe "With a private, user defined method" do before do @obj = use_module do attributes_for :user_with_a_private_method, :class => User do |u| u.key = a_private_method end - + private - + def a_private_method :private end end end - + it "should be able to call it" do user = @obj.new_user_with_a_private_method user.key.should == :private end end -end \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/public_methods_spec.rb b/spec/fixture_replacement/integration/public_methods_spec.rb index e0c1048..221162d 100644 --- a/spec/fixture_replacement/integration/public_methods_spec.rb +++ b/spec/fixture_replacement/integration/public_methods_spec.rb @@ -6,10 +6,10 @@ module FixtureReplacement obj = use_module do attributes_for :user end - + obj.public_methods.should include("create_user") end - + it "should respond_to? create_user" do obj = use_module do attributes_for :user @@ -18,4 +18,4 @@ module FixtureReplacement obj.respond_to?(:create_user).should be_true end end -end \ No newline at end of file +end diff --git a/spec/fixture_replacement/integration/valid_attributes_spec.rb b/spec/fixture_replacement/integration/valid_attributes_spec.rb index bcee88f..8a8c94b 100644 --- a/spec/fixture_replacement/integration/valid_attributes_spec.rb +++ b/spec/fixture_replacement/integration/valid_attributes_spec.rb @@ -6,36 +6,36 @@ module FixtureReplacement obj = use_module do attributes_for :user end - + obj.should respond_to(:valid_user_attributes) end - + it "should generate the method valid_member_attributes when attributes_for is specified" do obj = use_module do attributes_for :member end - + obj.should respond_to(:valid_member_attributes) end - + it "should have the attributes given as a hash" do obj = use_module do attributes_for :user do |x| x.key = 17 end end - + obj.valid_user_attributes.should include({ "key" => 17 }) end - + it "should have the attributes given" do obj = use_module do attributes_for :user do |x| x.key = 18 end end - + obj.valid_user_attributes.should include({ "key" => 18 }) end end -end \ No newline at end of file +end diff --git a/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb b/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb index d2cbeb0..6920bc5 100644 --- a/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb +++ b/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb @@ -14,33 +14,33 @@ # Open # Summary: # String.random in a STI base class works, but doesn't work with inherited classes -# +# # Detailed description -# +# # Love the plugin, but seem to have found a bug with the latest FixtureReplacemnt2. -# +# # There appears to be a problem when a base STI class in example_data has a random string. # The derived STI classes do not get a fresh random string with each call. -# +# # Eg. -# Given the below example_data.rb, repeated new_user/create_user will work fine. +# Given the below example_data.rb, repeated new_user/create_user will work fine. # Each call creating a new object with a new random string. -# +# # However the STI classes do not work as expected... # new_player/create_player will always return an object with the same random string -# -# +# +# # attributes_for :user do |u| # u.first_name = "First_name_" + String.random # u.email = "#{u.first_name}@aaa.com" # end -# +# # attributes_for :player, :from => :user, :class => Player -# -# +# +# # Thanks # Andy -# +# require File.dirname(__FILE__) + "/../../spec_helper" module FixtureReplacement @@ -55,17 +55,17 @@ module FixtureReplacement attributes_for :player, :class => Player, :from => :user end end - + it "should have a different string for each instance in the base class" do user1 = @obj.create_user user2 = @obj.create_user user1.username.should_not == user2.username end - + it "should have a different string for each instance in the inherited class (with STI)" do player1 = @obj.create_player player2 = @obj.create_player player1.username.should_not == player2.username end end -end \ No newline at end of file +end diff --git a/spec/spec_helpers.rb b/spec/spec_helpers.rb index c6dd4a0..21cd28d 100644 --- a/spec/spec_helpers.rb +++ b/spec/spec_helpers.rb @@ -3,7 +3,7 @@ def setup_database_connection require 'rubygems' require 'sqlite3' require 'active_record' - + ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:' ActiveRecord::Migration.verbose = false @@ -14,7 +14,7 @@ def setup_database_connection t.column :gender_id, :integer t.column :username, :string end - + create_table :players, :force => true do |t| t.column :username, :string t.column :key, :string @@ -34,7 +34,7 @@ def setup_database_connection t.column :username, :string t.column :key, :string t.column :other_key, :string - end + end create_table :items, :force => true do |t| t.column :category, :integer @@ -45,38 +45,38 @@ def setup_database_connection create_table :categories, :force => true do |t| t.column :name, :string end - + create_table :subscribers, :force => true do |t| t.column :first_name, :string end - + create_table :subscriptions, :force => true do |t| t.column :name, :string end - + create_table :subscribers_subscriptions, :force => true, :id => false do |t| t.column :subscriber_id, :integer t.column :subscription_id, :integer end - + create_table :events do |t| t.column :created_at, :datetime t.column :updated_at, :datetime end - + create_table :schedules do |t| t.integer :event_id end - + create_table :posts do |t| t.timestamps end - + create_table :comments do |t| t.integer :post_id t.timestamps end - + create_table :no_validations do |t| t.timestamps end @@ -84,28 +84,28 @@ def setup_database_connection create_table :validate_names do |t| t.string :name end - + create_table :validate_name_twos do |t| t.string :name end - + create_table :address_with_valid_cities do |t| t.string :city end - + create_table :address_with_valid_city_and_states do |t| t.string :city t.string :state end end - + def mock_fr_module(&block) mod = Module.new mod.extend(FixtureReplacement::ClassMethods) mod.instance_eval(&block) mod end - + def use_module(&block) mod = mock_fr_module(&block) diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 0fb3af5..f9fe487 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' module ::FixtureReplacement - + attributes_for :gender do |g| g.sex = "male" end @@ -11,7 +11,7 @@ module ::FixtureReplacement u.key = "something" u.gender = new_gender end - + private def scott "Scott Taylor" @@ -20,37 +20,37 @@ def scott class UserTest < Test::Unit::TestCase - + def setup extend FixtureReplacement end - + def test_true_should_be_true assert_equal true, true end - + def test_be_able_to_create_with_create_user assert_equal create_user.class, User end - + def test_user_has_default_gender_with_create_user assert create_user.gender.kind_of?(Gender) assert_equal create_user.gender.sex, "male" end - + def test_user_has_default_gender_with_new_user assert new_user.gender.kind_of?(Gender) assert_equal new_user.gender.sex, "male" - end - + end + def test_create_user_should_have_user_key_something assert_equal create_user.key, "something" end - + def test_new_user_should_have_user_key_something assert_equal new_user.key, "something" end - + def test_testcase_should_not_raise_an_error_when_sending_new_user assert self.send(:new_user) end From 4beaf6b5ba22f6ba9d73ce71f3bd29f22084ccf7 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:12:22 -0500 Subject: [PATCH 18/24] Convert tabs to spaces --- etc/bug_reports/2007_09_28_linoj.txt | 2 +- ...2007_09_14_default_model_name_with_arguments.diff | 4 ++-- etc/patches/2007_10_14_active_record_specs.diff | 4 ++-- etc/patches/2007_10_14_protected_attributes.diff | 4 ++-- etc/patches/2007_10_14_send_patch.diff | 8 ++++---- .../2007_10_14_spelling_error_in_comments.diff | 4 ++-- .../2007_10_17_protected_attributes_second_go.diff | 12 ++++++------ etc/patches/2007_10_18_README.diff | 4 ++-- etc/patches/2007_10_19_readme_tweak.diff | 4 ++-- etc/patches/2007_10_19_silence_migration.diff | 4 ++-- .../2007_10_25_changed_classify_to_camelize.diff | 8 ++++---- ...rator_should_not_reload_environment_or_boot.patch | 4 ++-- ..._11_20_string_random_refactor_and_extension.patch | 8 ++++---- ..._20_string_random_refactor_and_extension_v2.patch | 8 ++++---- .../2008_01_21_random_string_with_sti_spec.rb | 6 +++--- 15 files changed, 42 insertions(+), 42 deletions(-) diff --git a/etc/bug_reports/2007_09_28_linoj.txt b/etc/bug_reports/2007_09_28_linoj.txt index 2bbdbc1..458468d 100644 --- a/etc/bug_reports/2007_09_28_linoj.txt +++ b/etc/bug_reports/2007_09_28_linoj.txt @@ -10,7 +10,7 @@ Then I installed validates_email_format_of plugin http://code.dunae.ca/validates_email_format_of and added this to my User model - validates_email_format_of :email + validates_email_format_of :email then script/server wont start When I comment out this line, it's fine diff --git a/etc/patches/2007_09_14_default_model_name_with_arguments.diff b/etc/patches/2007_09_14_default_model_name_with_arguments.diff index 7216f07..02671d3 100644 --- a/etc/patches/2007_09_14_default_model_name_with_arguments.diff +++ b/etc/patches/2007_09_14_default_model_name_with_arguments.diff @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb =================================================================== ---- lib/fixture_replacement/fixture_replacement.rb (revision 1151) -+++ lib/fixture_replacement/fixture_replacement.rb (working copy) +--- lib/fixture_replacement/fixture_replacement.rb (revision 1151) ++++ lib/fixture_replacement/fixture_replacement.rb (working copy) @@ -40,7 +40,8 @@ def merge_unevaluated_method(obj, method_for_instantiation, hash={}) hash.each do |key, value| diff --git a/etc/patches/2007_10_14_active_record_specs.diff b/etc/patches/2007_10_14_active_record_specs.diff index 7a9211a..64e30b3 100644 --- a/etc/patches/2007_10_14_active_record_specs.diff +++ b/etc/patches/2007_10_14_active_record_specs.diff @@ -1,7 +1,7 @@ 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) +--- spec/fixture_replacement/fixture_replacement_spec.rb (revision 31) ++++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy) @@ -1,53 +1,52 @@ - require File.dirname(__FILE__) + "/../spec_helper" diff --git a/etc/patches/2007_10_14_protected_attributes.diff b/etc/patches/2007_10_14_protected_attributes.diff index 546ad27..0ae689b 100644 --- a/etc/patches/2007_10_14_protected_attributes.diff +++ b/etc/patches/2007_10_14_protected_attributes.diff @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb =================================================================== ---- lib/fixture_replacement/fixture_replacement.rb (revision 31) -+++ lib/fixture_replacement/fixture_replacement.rb (working copy) +--- lib/fixture_replacement/fixture_replacement.rb (revision 31) ++++ lib/fixture_replacement/fixture_replacement.rb (working copy) @@ -70,7 +70,9 @@ hash_given = args[0] || Hash.new merged_hash = self.send(attributes_method).merge(hash_given) diff --git a/etc/patches/2007_10_14_send_patch.diff b/etc/patches/2007_10_14_send_patch.diff index e201d7e..9bfb9f2 100644 --- a/etc/patches/2007_10_14_send_patch.diff +++ b/etc/patches/2007_10_14_send_patch.diff @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb =================================================================== ---- lib/fixture_replacement/fixture_replacement.rb (revision 31) -+++ lib/fixture_replacement/fixture_replacement.rb (working copy) +--- lib/fixture_replacement/fixture_replacement.rb (revision 31) ++++ lib/fixture_replacement/fixture_replacement.rb (working copy) @@ -70,7 +70,9 @@ hash_given = args[0] || Hash.new merged_hash = self.send(attributes_method).merge(hash_given) @@ -26,8 +26,8 @@ Index: lib/fixture_replacement/fixture_replacement.rb end 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) +--- 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 diff --git a/etc/patches/2007_10_14_spelling_error_in_comments.diff b/etc/patches/2007_10_14_spelling_error_in_comments.diff index 2072da2..07acc9d 100644 --- a/etc/patches/2007_10_14_spelling_error_in_comments.diff +++ b/etc/patches/2007_10_14_spelling_error_in_comments.diff @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb =================================================================== ---- lib/fixture_replacement/fixture_replacement.rb (revision 31) -+++ lib/fixture_replacement/fixture_replacement.rb (working copy) +--- lib/fixture_replacement/fixture_replacement.rb (revision 31) ++++ lib/fixture_replacement/fixture_replacement.rb (working copy) @@ -22,7 +22,7 @@ end diff --git a/etc/patches/2007_10_17_protected_attributes_second_go.diff b/etc/patches/2007_10_17_protected_attributes_second_go.diff index 8cd24fc..8824efe 100644 --- a/etc/patches/2007_10_17_protected_attributes_second_go.diff +++ b/etc/patches/2007_10_17_protected_attributes_second_go.diff @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb =================================================================== ---- lib/fixture_replacement/fixture_replacement.rb (revision 52) -+++ lib/fixture_replacement/fixture_replacement.rb (working copy) +--- lib/fixture_replacement/fixture_replacement.rb (revision 52) ++++ lib/fixture_replacement/fixture_replacement.rb (working copy) @@ -70,7 +70,12 @@ hash_given = args[0] || Hash.new merged_hash = self.send(attributes_method).merge(hash_given) @@ -31,8 +31,8 @@ Index: lib/fixture_replacement/fixture_replacement.rb end Index: spec/fixture_replacement/fixture_replacement_spec.rb =================================================================== ---- spec/fixture_replacement/fixture_replacement_spec.rb (revision 52) -+++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy) +--- spec/fixture_replacement/fixture_replacement_spec.rb (revision 52) ++++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy) @@ -9,9 +9,88 @@ belongs_to :gender end @@ -196,8 +196,8 @@ Index: spec/fixture_replacement/fixture_replacement_spec.rb end Index: spec/spec_helper.rb =================================================================== ---- spec/spec_helper.rb (revision 52) -+++ spec/spec_helper.rb (working copy) +--- spec/spec_helper.rb (revision 52) ++++ spec/spec_helper.rb (working copy) @@ -21,6 +21,11 @@ t.column :gender_id, :string end diff --git a/etc/patches/2007_10_18_README.diff b/etc/patches/2007_10_18_README.diff index db333b1..6fa86fb 100644 --- a/etc/patches/2007_10_18_README.diff +++ b/etc/patches/2007_10_18_README.diff @@ -1,7 +1,7 @@ Index: README =================================================================== ---- README (revision 60) -+++ README (working copy) +--- README (revision 60) ++++ README (working copy) @@ -1,32 +1,92 @@ = FixtureReplacement diff --git a/etc/patches/2007_10_19_readme_tweak.diff b/etc/patches/2007_10_19_readme_tweak.diff index ccf2d6a..0a9e7f2 100644 --- a/etc/patches/2007_10_19_readme_tweak.diff +++ b/etc/patches/2007_10_19_readme_tweak.diff @@ -1,7 +1,7 @@ Index: README =================================================================== ---- README (revision 65) -+++ README (working copy) +--- README (revision 65) ++++ README (working copy) @@ -144,7 +144,6 @@ - default_* methods can take a hash (applied in rev. 11) - Wincent Colaiuta (Huge Thanks) diff --git a/etc/patches/2007_10_19_silence_migration.diff b/etc/patches/2007_10_19_silence_migration.diff index eed2475..73b78c3 100644 --- a/etc/patches/2007_10_19_silence_migration.diff +++ b/etc/patches/2007_10_19_silence_migration.diff @@ -1,7 +1,7 @@ Index: spec/spec_helper.rb =================================================================== ---- spec/spec_helper.rb (revision 65) -+++ spec/spec_helper.rb (working copy) +--- spec/spec_helper.rb (revision 65) ++++ spec/spec_helper.rb (working copy) @@ -5,6 +5,7 @@ ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:' diff --git a/etc/patches/2007_10_25_changed_classify_to_camelize.diff b/etc/patches/2007_10_25_changed_classify_to_camelize.diff index c9a58ba..9aea451 100644 --- a/etc/patches/2007_10_25_changed_classify_to_camelize.diff +++ b/etc/patches/2007_10_25_changed_classify_to_camelize.diff @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/fixture_replacement.rb =================================================================== ---- lib/fixture_replacement/fixture_replacement.rb (revision 70) -+++ lib/fixture_replacement/fixture_replacement.rb (working copy) +--- 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) @@ -13,8 +13,8 @@ Index: lib/fixture_replacement/fixture_replacement.rb add_to_class_singleton(@model_class) Index: spec/fixture_replacement/fixture_replacement_spec.rb =================================================================== ---- spec/fixture_replacement/fixture_replacement_spec.rb (revision 70) -+++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy) +--- spec/fixture_replacement/fixture_replacement_spec.rb (revision 70) ++++ spec/fixture_replacement/fixture_replacement_spec.rb (working copy) @@ -14,6 +14,7 @@ end diff --git a/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch b/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch index 9d47658..2934bde 100644 --- a/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch +++ b/etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch @@ -1,7 +1,7 @@ Index: vendor/plugins/fixture_replacement/generators/fixture_replacement/fixture_replacement_generator.rb =================================================================== ---- vendor/plugins/fixture_replacement/generators/fixture_replacement/fixture_replacement_generator.rb (revision 83) -+++ vendor/plugins/fixture_replacement/generators/fixture_replacement/fixture_replacement_generator.rb (working copy) +--- vendor/plugins/fixture_replacement/generators/fixture_replacement/fixture_replacement_generator.rb (revision 83) ++++ vendor/plugins/fixture_replacement/generators/fixture_replacement/fixture_replacement_generator.rb (working copy) @@ -1,6 +1,6 @@ require 'rbconfig' -require 'config/boot' diff --git a/etc/patches/2007_11_20_string_random_refactor_and_extension.patch b/etc/patches/2007_11_20_string_random_refactor_and_extension.patch index 01028e4..60ef1d6 100644 --- a/etc/patches/2007_11_20_string_random_refactor_and_extension.patch +++ b/etc/patches/2007_11_20_string_random_refactor_and_extension.patch @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/string.rb =================================================================== ---- lib/fixture_replacement/string.rb (revision 83) -+++ lib/fixture_replacement/string.rb (working copy) +--- lib/fixture_replacement/string.rb (revision 83) ++++ lib/fixture_replacement/string.rb (working copy) @@ -1,10 +1,21 @@ +class String + def random_chr @@ -32,8 +32,8 @@ Index: lib/fixture_replacement/string.rb - Index: spec/fixture_replacement/extentions_spec.rb =================================================================== ---- spec/fixture_replacement/extentions_spec.rb (revision 83) -+++ spec/fixture_replacement/extentions_spec.rb (working copy) +--- spec/fixture_replacement/extentions_spec.rb (revision 83) ++++ spec/fixture_replacement/extentions_spec.rb (working copy) @@ -2,7 +2,9 @@ describe "String.random" do diff --git a/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch b/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch index 35a5834..e13d4fc 100644 --- a/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch +++ b/etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch @@ -1,7 +1,7 @@ Index: lib/fixture_replacement/string.rb =================================================================== ---- lib/fixture_replacement/string.rb (revision 83) -+++ lib/fixture_replacement/string.rb (working copy) +--- lib/fixture_replacement/string.rb (revision 83) ++++ lib/fixture_replacement/string.rb (working copy) @@ -1,10 +1,25 @@ +class String + def random_chr @@ -36,8 +36,8 @@ Index: lib/fixture_replacement/string.rb - Index: spec/fixture_replacement/extentions_spec.rb =================================================================== ---- spec/fixture_replacement/extentions_spec.rb (revision 83) -+++ spec/fixture_replacement/extentions_spec.rb (working copy) +--- spec/fixture_replacement/extentions_spec.rb (revision 83) ++++ spec/fixture_replacement/extentions_spec.rb (working copy) @@ -2,7 +2,9 @@ describe "String.random" do diff --git a/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb b/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb index 6920bc5..5feb0d2 100644 --- a/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb +++ b/spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb @@ -4,13 +4,13 @@ # # [#17249] String.random in a STI base class works, but doesn't work with inherited classes # Date: -# 2008-01-20 14:01 Priority: +# 2008-01-20 14:01 Priority: # 3 # Submitted By: -# andy watts (andywatts) Assigned To: +# andy watts (andywatts) Assigned To: # Nobody (None) # Category: -# Console (script/console) State: +# Console (script/console) State: # Open # Summary: # String.random in a STI base class works, but doesn't work with inherited classes From aac735710afd35cdebc3a5123f9a43a7bb689bc8 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:13:49 -0500 Subject: [PATCH 19/24] Add wincent to contributor list --- contributions.rdoc | 1 + 1 file changed, 1 insertion(+) diff --git a/contributions.rdoc b/contributions.rdoc index 8237b2b..b585369 100644 --- a/contributions.rdoc +++ b/contributions.rdoc @@ -38,6 +38,7 @@ Thanks to the following for making this software better: - patch to ignore attr_protected in mass assignment (applied in revision 57) - Most of this README Documentation (applied in revision 62) - patch: silencing sqlite3 in memory creation of table output (applied in revision 72) + - doc patch: typo fix in readme - Carl Porth - patch: classify should be camelize (applied in revision 74) - LinoJ, JW, Matthew Bass, Andy Watts, Dave Spurr From a44a287dc02303bc2da060d647a57bc133ced2c1 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:17:02 -0500 Subject: [PATCH 20/24] No newline at end of VERSION file --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4a36342..56fea8a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0 +3.0.0 \ No newline at end of file From b1541038f35a908a6eaa12cef03115fb5940f7cf Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:17:46 -0500 Subject: [PATCH 21/24] Update docs with gem instructions --- CHANGELOG.rdoc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 7d7d696..7200906 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,5 +1,12 @@ == HEAD +- Made it into a rubygem. Get it from gemcutter: + + gem install fixture_replacement + + You'll need to require "fixture_replacement" (or load "fixture_replacement") + in your spec_helper, test_helper, or anywhere else you plan to use it. + - validate instances with FixtureReplacement.validate! == 3.0.0 From 9b7aa57ea43e1fa5ea17218d4d86c465374c2d0a Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:19:41 -0500 Subject: [PATCH 22/24] version bump: 3.0.1 --- CHANGELOG.rdoc | 2 +- README.rdoc | 2 +- VERSION | 2 +- lib/fixture_replacement/version.rb | 2 +- spec/fixture_replacement/version_spec.rb | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 7200906..c5da7ce 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,4 +1,4 @@ -== HEAD +== 3.0.1 - Made it into a rubygem. Get it from gemcutter: diff --git a/README.rdoc b/README.rdoc index 1fd49db..9147b3e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,4 +1,4 @@ -= FixtureReplacement (version 3.0) += FixtureReplacement (version 3.0.1) == What is FixtureReplacement diff --git a/VERSION b/VERSION index 56fea8a..13d683c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.0 \ No newline at end of file +3.0.1 \ No newline at end of file diff --git a/lib/fixture_replacement/version.rb b/lib/fixture_replacement/version.rb index 99834b5..97746ff 100644 --- a/lib/fixture_replacement/version.rb +++ b/lib/fixture_replacement/version.rb @@ -3,7 +3,7 @@ module Version unless defined?(FixtureReplacement::VERSION) MAJOR = 3 MINOR = 0 - TINY = 0 + TINY = 1 version_string = "#{MAJOR}.#{MINOR}.#{TINY}" version_string << " RC#{RELEASE_CANDIDATE}" if defined?(RELEASE_CANDIDATE) diff --git a/spec/fixture_replacement/version_spec.rb b/spec/fixture_replacement/version_spec.rb index 24ddd72..14af816 100644 --- a/spec/fixture_replacement/version_spec.rb +++ b/spec/fixture_replacement/version_spec.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + "/../spec_helper" describe FixtureReplacement do - it "should be at version 3.0.0" do - FixtureReplacement::VERSION.should == "3.0.0" + it "should be at version 3.0.1" do + FixtureReplacement::VERSION.should == "3.0.1" end end From eb1175dd303ffbf0a4c2befbdd87846b489e0d7c Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:19:54 -0500 Subject: [PATCH 23/24] Add gemspec. Closes Github #3 --- fixture_replacement.gemspec | 125 ++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 fixture_replacement.gemspec diff --git a/fixture_replacement.gemspec b/fixture_replacement.gemspec new file mode 100644 index 0000000..da2bc54 --- /dev/null +++ b/fixture_replacement.gemspec @@ -0,0 +1,125 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE +# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec` +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{fixture_replacement} + s.version = "3.0.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Scott Taylor"] + s.date = %q{2009-11-21} + s.description = %q{FixtureReplacement is a Rails 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. +} + s.email = %q{scott@railsnewbie.com} + s.extra_rdoc_files = [ + "README.rdoc" + ] + s.files = [ + ".gitignore", + "CHANGELOG.rdoc", + "GPL_LICENSE", + "MIT_LICENSE", + "README.rdoc", + "Rakefile", + "TODO.rdoc", + "VERSION", + "contributions.rdoc", + "etc/bug_reports/2007_09_28_linoj.txt", + "etc/google_analytics", + "etc/patches/2007_09_14_default_model_name_with_arguments.diff", + "etc/patches/2007_10_14_active_record_specs.diff", + "etc/patches/2007_10_14_protected_attributes.diff", + "etc/patches/2007_10_14_send_patch.diff", + "etc/patches/2007_10_14_spelling_error_in_comments.diff", + "etc/patches/2007_10_17_protected_attributes_second_go.diff", + "etc/patches/2007_10_18_README.diff", + "etc/patches/2007_10_19_readme_tweak.diff", + "etc/patches/2007_10_19_silence_migration.diff", + "etc/patches/2007_10_25_changed_classify_to_camelize.diff", + "etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch", + "etc/patches/2007_11_20_string_random_refactor_and_extension.patch", + "etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch", + "lib/fixture_replacement.rb", + "lib/fixture_replacement/attribute_builder.rb", + "lib/fixture_replacement/class_methods.rb", + "lib/fixture_replacement/method_generator.rb", + "lib/fixture_replacement/version.rb", + "lib/fr.rb", + "philosophy_and_bugs.rdoc", + "rake_tasks/code_quality.rb", + "rake_tasks/docs.rb", + "rake_tasks/gem.rb", + "rake_tasks/specs.rb", + "rake_tasks/tests.rb", + "rake_tasks/website.rb", + "spec/fixture_replacement/attribute_builder_spec.rb", + "spec/fixture_replacement/fixture_replacement_spec.rb", + "spec/fixture_replacement/fixtures/classes.rb", + "spec/fixture_replacement/fr_spec.rb", + "spec/fixture_replacement/integration/attr_protected_attributes_spec.rb", + "spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb", + "spec/fixture_replacement/integration/attributes_from_spec_without_block.rb", + "spec/fixture_replacement/integration/create_method_spec.rb", + "spec/fixture_replacement/integration/cyclic_dependency_spec.rb", + "spec/fixture_replacement/integration/default_warnings_spec.rb", + "spec/fixture_replacement/integration/extend_spec.rb", + "spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb", + "spec/fixture_replacement/integration/new_method_spec.rb", + "spec/fixture_replacement/integration/private_methods_spec.rb", + "spec/fixture_replacement/integration/public_methods_spec.rb", + "spec/fixture_replacement/integration/valid_attributes_spec.rb", + "spec/fixture_replacement/integration/validation_spec.rb", + "spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb", + "spec/fixture_replacement/version_spec.rb", + "spec/spec.opts", + "spec/spec_helper.rb", + "spec/spec_helpers.rb", + "test/test_helper.rb", + "test/unit/user_test.rb" + ] + s.homepage = %q{http://replacefixtures.rubyforge.org} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.5} + s.summary = %q{The original fixture replacement solution for rails} + s.test_files = [ + "spec/fixture_replacement/attribute_builder_spec.rb", + "spec/fixture_replacement/fixture_replacement_spec.rb", + "spec/fixture_replacement/fixtures/classes.rb", + "spec/fixture_replacement/fr_spec.rb", + "spec/fixture_replacement/integration/attr_protected_attributes_spec.rb", + "spec/fixture_replacement/integration/attributes_for_with_invalid_keys_spec.rb", + "spec/fixture_replacement/integration/attributes_from_spec_without_block.rb", + "spec/fixture_replacement/integration/create_method_spec.rb", + "spec/fixture_replacement/integration/cyclic_dependency_spec.rb", + "spec/fixture_replacement/integration/default_warnings_spec.rb", + "spec/fixture_replacement/integration/extend_spec.rb", + "spec/fixture_replacement/integration/has_and_belongs_to_many_spec.rb", + "spec/fixture_replacement/integration/new_method_spec.rb", + "spec/fixture_replacement/integration/private_methods_spec.rb", + "spec/fixture_replacement/integration/public_methods_spec.rb", + "spec/fixture_replacement/integration/valid_attributes_spec.rb", + "spec/fixture_replacement/integration/validation_spec.rb", + "spec/fixture_replacement/regressions/2008_01_21_random_string_with_sti_spec.rb", + "spec/fixture_replacement/version_spec.rb", + "spec/spec_helper.rb", + "spec/spec_helpers.rb", + "test/test_helper.rb", + "test/unit/user_test.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + else + end + else + end +end From dc1f42d718bfa2823852e4659480cc8b81dd8a85 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 21 Nov 2009 03:24:08 -0500 Subject: [PATCH 24/24] Update gemspec --- fixture_replacement.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/fixture_replacement.gemspec b/fixture_replacement.gemspec index da2bc54..43d3efd 100644 --- a/fixture_replacement.gemspec +++ b/fixture_replacement.gemspec @@ -44,6 +44,7 @@ reference other models) and add new objects on the fly. "etc/patches/2007_11_20_fixture_replacement_generator_should_not_reload_environment_or_boot.patch", "etc/patches/2007_11_20_string_random_refactor_and_extension.patch", "etc/patches/2007_11_20_string_random_refactor_and_extension_v2.patch", + "fixture_replacement.gemspec", "lib/fixture_replacement.rb", "lib/fixture_replacement/attribute_builder.rb", "lib/fixture_replacement/class_methods.rb",