merb-fixtures-gogolok 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. data/LICENSE +20 -0
  2. data/README +74 -0
  3. data/Rakefile +53 -0
  4. data/TODO +5 -0
  5. data/lib/merb-fixtures.rb +36 -0
  6. data/lib/merb-fixtures/activerecord/activerecord.rb +1 -0
  7. data/lib/merb-fixtures/activerecord/merbtasks.rb +3 -0
  8. data/lib/merb-fixtures/datamapper/datamapper.rb +5 -0
  9. data/lib/merb-fixtures/datamapper/merbtasks.rb +3 -0
  10. data/lib/merb-fixtures/extensions/object_space.rb +7 -0
  11. data/lib/merb-fixtures/sequel/merbtasks.rb +3 -0
  12. data/lib/merb-fixtures/sequel/sequel.rb +1 -0
  13. data/lib/merb-fixtures/shared/exceptions.rb +1 -0
  14. data/lib/merb-fixtures/shared/extensions.rb +36 -0
  15. data/lib/merb-fixtures/shared/fixture.rb +25 -0
  16. data/lib/merb-fixtures/shared/fixtures.rb +31 -0
  17. data/lib/merb-fixtures/shared/helpers.rb +21 -0
  18. data/lib/merb-fixtures/shared/kernel.rb +56 -0
  19. data/lib/merb-fixtures/shared/merbtasks.rb +30 -0
  20. data/lib/merb-fixtures/shared/orm.rb +43 -0
  21. data/spec/merb-fixtures/activerecord/activerecord_spec.rb +1 -0
  22. data/spec/merb-fixtures/datamapper/datamapper_spec.rb +42 -0
  23. data/spec/merb-fixtures/extensions/object_space_spec.rb +0 -0
  24. data/spec/merb-fixtures/sequel/sequel_spec.rb +0 -0
  25. data/spec/merb-fixtures/shared/errors_spec.rb +0 -0
  26. data/spec/merb-fixtures/shared/extensions_spec.rb +0 -0
  27. data/spec/merb-fixtures/shared/fixture_spec.rb +49 -0
  28. data/spec/merb-fixtures/shared/fixtures_spec.rb +0 -0
  29. data/spec/merb-fixtures/shared/helpers_spec.rb +0 -0
  30. data/spec/merb-fixtures/shared/kernel_spec.rb +17 -0
  31. data/spec/merb-fixtures/shared/orm_spec.rb +39 -0
  32. data/spec/spec_helper.rb +33 -0
  33. metadata +90 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Jakub Šťastný aka Botanicus
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,74 @@
1
+ === About ===
2
+ Fixtures is Merb plugin which provides fixture system for Merb.
3
+ 1) Fixtures are written in Ruby, not in YAML, so it's more powerful than YAML one. For example it's much easier to add HABTM relationships.
4
+ 2) Fixtures aren't just for testing, but they are useful for development and even for migrations
5
+
6
+ === Setup ===
7
+ git clone git://github.com/botanicus/merb-fixtures.git
8
+ cd merb-fixtures
9
+ rake install
10
+
11
+ # config/init.rb
12
+ dependency 'merb-fixtures'
13
+
14
+ By default, fixtures folder is app/fixtures. If you like to puts your fixtures on other place, feel free to change it in your init.rb:
15
+ # config/init.rb
16
+ Merb::Plugins.config[:fixtures] = {
17
+ :directory => Merb.root / "app" / "fixtures"
18
+ }
19
+
20
+ === Writing fixtures ===
21
+ First you must write a fixture:
22
+ # app/fixtures/author.rb
23
+ fixture_for(Author, :botanicus) do
24
+ self.first_name = "Jakub"
25
+ self.last_name = "Šťastný"
26
+ self.nickname = "Botanicus"
27
+ self.homepage = "http://botablog.cz"
28
+ self.posts = [ ... ]
29
+ end
30
+
31
+ === Usage from merb console or specs ===
32
+ Now you can use it - from your specs or just from merb console:
33
+ # Get fixture named :botanicus
34
+ Author.fixture(:botanicus)
35
+ => #<Author last_name="Šťastný" homepage="http://botablog.cz" first_name="Jakub" nickname="Botanicus">
36
+
37
+ # Get all the author's fixtures
38
+ Author.fixtures
39
+ => [#<Author last_name="Šťastný" homepage="http://botablog.cz" first_name="Jakub" nickname="Botanicus">]
40
+
41
+ === Usage in migrations ===
42
+ # Usage in migrations
43
+ migration 1, "Add default author" do
44
+ up do
45
+ Author.fixture(:botanicus).save
46
+ end
47
+ down do
48
+ # foo
49
+ end
50
+ end
51
+
52
+ === FAQ ===
53
+
54
+ == HABTM ==
55
+ # TODO: describe different types of associations
56
+ class ModelOne
57
+ has 0..n, :model_two
58
+ end
59
+
60
+ class ModelTwo
61
+ belongs_to :model_one
62
+ # model_one_id
63
+ end
64
+
65
+ fixture_for(ModelOne, :one) do
66
+ # foo bar
67
+ end
68
+
69
+ require_fixtures :model_one
70
+ fixture_for(ModelTwo, :two) do
71
+ self.model_one = ModelOne.fixture(:model_one)
72
+ end
73
+
74
+ 1) save ModelOne
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'base64'
6
+ require 'merb-core/version'
7
+
8
+ NAME = "merb-fixtures-gogolok"
9
+ GEM_VERSION = "0.9.5"
10
+ AUTHOR = "Jakub Šťastný"
11
+ EMAIL = Base64.decode64("a25hdmEuYmVzdHZpbmVuc2lAZ21haWwuY29t\n")
12
+ HOMEPAGE = "http://botablog.cz/"
13
+ SUMMARY = "Merb plugin that provides flexible fixtures system. DataMapper, ActiveRecord and Sequel is supported."
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.rubyforge_project = 'merb'
17
+ s.name = NAME
18
+ s.version = GEM_VERSION
19
+ s.platform = Gem::Platform::RUBY
20
+ s.has_rdoc = true
21
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
22
+ s.summary = SUMMARY
23
+ s.description = s.summary
24
+ s.author = AUTHOR
25
+ s.email = EMAIL
26
+ s.homepage = HOMEPAGE
27
+ # s.add_dependency('merb', '>= 0.9.4')
28
+ s.require_path = 'lib'
29
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
30
+ end
31
+
32
+ Rake::GemPackageTask.new(spec) do |pkg|
33
+ pkg.gem_spec = spec
34
+ end
35
+
36
+ desc "install the plugin locally"
37
+ task :install => [:package] do
38
+ sh %{#{sudo} gem install #{install_home} pkg/#{NAME}-#{GEM_VERSION} --no-update-sources}
39
+ end
40
+
41
+ desc "create a gemspec file"
42
+ task :make_spec do
43
+ File.open("#{NAME}.gemspec", "w") do |file|
44
+ file.puts spec.to_ruby
45
+ end
46
+ end
47
+
48
+ namespace :jruby do
49
+ desc "Run :package and install the resulting .gem with jruby"
50
+ task :install => :package do
51
+ sh %{#{sudo} jruby -S gem install #{install_home} pkg/#{NAME}-#{GEM_VERSION}.gem --no-rdoc --no-ri}
52
+ end
53
+ end
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ - Documentation
2
+ - Update specs
3
+ - Anonymous fixtures
4
+ - Fixtures dependencies (because of HABTM)
5
+ - Do specs for tasks
@@ -0,0 +1,36 @@
1
+ if defined?(Merb::Plugins)
2
+ def require_fixture_files
3
+ libraries = %w(exceptions kernel fixture fixtures helpers extensions orm)
4
+ libraries.each { |library| require "merb-fixtures/shared/#{library}" }
5
+ require "merb-fixtures/#{ORM}/#{ORM}"
6
+ end
7
+
8
+ # Configuration and initialization
9
+ # For development - you can use dependency "/Users/..."
10
+ # Why it isn't done automatically? "." really is in load paths,
11
+ # but require is done from /usr/bin/merb and "." is /usr/bin
12
+ # ... at least I think so :)
13
+ $: << File.dirname(__FILE__)
14
+ ORM = Merb.orm
15
+ default = {
16
+ :directory => Merb.root / "app" / "fixtures",
17
+ :autoload => true,
18
+ :helpers => true }
19
+ # TODO: send a Merb patch for this
20
+ Merb::Plugins.config[:fixtures] = default.merge(Merb::Plugins.config[:fixtures] || {})
21
+
22
+ # Fixture loading
23
+ Merb::BootLoader.after_app_loads do
24
+ require_fixture_files
25
+ if Merb::Plugins.config[:fixtures][:autoload]
26
+ Merb::Fixtures.load
27
+ end
28
+ end
29
+
30
+ # Rakefiles
31
+ Merb::Plugins.add_rakefiles("merb-fixtures/shared/merbtasks", "merb-fixtures/#{ORM}/merbtasks")
32
+ # It couldn't works, it can work just after app load
33
+ # if Pathname($0).basename.to_s.eql?("rake")
34
+ # require_fixture_files
35
+ # end
36
+ end
@@ -0,0 +1 @@
1
+ ActiveRecord::Base.send(:include, Merb::Fixtures::Extensions)
@@ -0,0 +1,3 @@
1
+ # Reload tasks
2
+ desc "Reload the fixtures from database. Warning: it recreate the database!"
3
+ task "db:fixtures:reload" => ["db:create", "db:migrate", "db:fixtures:load"]
@@ -0,0 +1,5 @@
1
+ # FIXME: find better way how to do it. Problems: when user add a model, he must restart his application.
2
+ require "merb-fixtures/shared/orm"
3
+ Merb::Fixtures::ORM.models.each do |model|
4
+ model.send(:include, Merb::Fixtures::Extensions)
5
+ end
@@ -0,0 +1,3 @@
1
+ # Reload tasks
2
+ desc "Reload the fixtures from database. Warning: it recreate the database!"
3
+ task "dm:db:fixtures:reload" => ["dm:db:automigrate", "dm:db:migrate:up", "dm:db:fixtures:load"]
@@ -0,0 +1,7 @@
1
+ module ObjectSpace
2
+ def self.each_class(&block)
3
+ ObjectSpace.each_object(Class) do |klass|
4
+ block.call(klass) if block_given?
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ # Reload tasks
2
+ desc "Reload the fixtures from database. Warning: it recreate the database!"
3
+ task "sequel:db:fixtures:reload" => ["sequel:db:migrate", "sequel:db:fixtures:load"]
@@ -0,0 +1 @@
1
+ Sequel::Model.send(:include, Merb::Fixtures::Extensions)
@@ -0,0 +1 @@
1
+ class FixturesDirectoryNotFound < StandardError ; end
@@ -0,0 +1,36 @@
1
+ require "merb-fixtures/shared/fixture"
2
+
3
+ module Merb
4
+ module Fixtures
5
+ module Extensions
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ # Post.fixture(:botanicus)
12
+ def fixture(name)
13
+ self.init
14
+ name ? @fixture.load(name) : @fixture
15
+ end
16
+
17
+ # Post.get_fixture.create(:botanicus, Author.new)
18
+ def get_fixture
19
+ self.init
20
+ return @fixture
21
+ end
22
+
23
+ # Post.fixtures => {:name => object}
24
+ def fixtures
25
+ self.init
26
+ return @fixture.objects
27
+ end
28
+
29
+ protected
30
+ def init
31
+ @fixture ||= Merb::Fixtures::Fixture.new
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ require "merb-fixtures/shared/orm"
2
+
3
+ module Merb
4
+ module Fixtures
5
+ class Fixture
6
+ def initialize
7
+ @fixtures = Hash.new
8
+ end
9
+
10
+ # Fixture.create(:botanicus, Author.new)
11
+ def create(name, object)
12
+ @fixtures[name] = object
13
+ end
14
+
15
+ # Fixture.load(:botanicus)
16
+ def load(name)
17
+ return @fixtures[name] #rescue nil
18
+ end
19
+
20
+ def objects
21
+ @fixtures
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ module Merb
2
+ module Fixtures
3
+ class << self
4
+ def load
5
+ Merb.logger.debug("Loading fixtures ...")
6
+ unless Merb.env?("production")
7
+ directory = Merb::Plugins.config[:fixtures][:directory]
8
+ if File.exist?(directory)
9
+ Dir[directory/"*.rb"].each do |file|
10
+ Kernel.load(file)
11
+ end
12
+ else
13
+ raise FixturesDirectoryNotFound
14
+ end
15
+ end
16
+ end
17
+
18
+ alias :reload :load
19
+
20
+ def all
21
+ output = Hash.new
22
+ ORM.models.each { |model| output.merge!(model.fixtures) unless model.fixtures.values.empty? }
23
+ return output
24
+ end
25
+
26
+ def save
27
+ Merb::Fixtures.all.each { |name, fixture| fixture.save rescue raise "Fixture #{name} (model #{fixture.class}) couldn't be saved!"}
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module Merb
2
+ module Fixtures
3
+ module Helpers
4
+ LOREM = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
5
+ # lorem :type => "html", :count => 5
6
+ def lorem(params = Hash.new)
7
+ output = Array.new
8
+ default = { :count => 1, :type => "plain" }
9
+ params = params.merge(default)
10
+ params[:count].times do
11
+ if params[:type].to_s.eql?("html")
12
+ output.push("<p>#{LOREM}</p>")
13
+ else
14
+ output.push(LOREM)
15
+ end
16
+ end
17
+ return output
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,56 @@
1
+ module Kernel
2
+ # Create new fixture for given model.
3
+ #
4
+ # ==== Parameters
5
+ # klass<Class>::
6
+ # Model class
7
+ # name<Symbol>::
8
+ # Name of the fixture object.
9
+ # Examples: :first_post, :default_author
10
+ #
11
+ # ==== Returns
12
+ # Merb::Fixtures::Fixture::
13
+ # Fixture for given model with given name.
14
+ #
15
+ # ==== Example
16
+ # fixture_for Author, :botanicus do
17
+ # self.first_name = Jakub
18
+ # self.last_name = Šťastný
19
+ # end
20
+ # -
21
+ # @public
22
+ def fixture_for(klass, name = nil, &block)
23
+ include Merb::Fixtures::Helpers if Merb::Plugins.config[:fixtures]
24
+ instance = klass.new # Post.new
25
+ instance.instance_eval(&block) if block_given?
26
+ klass.get_fixture.create(name, instance)
27
+ return instance
28
+ end
29
+
30
+ # Great for test/spec:
31
+ # Load answer.rb fixture:
32
+ # fixture(:answer)
33
+ # fixture(:answer, :ruby)
34
+ # Do NOT use this in your fixture files!
35
+ def load_fixtures(*fixtures)
36
+ do_some_with_fixtures(fixtures) do |directory, fixture|
37
+ load directory/fixture
38
+ end
39
+ end
40
+
41
+ # Use it in your fixture files
42
+ def require_fixtures(*fixtures)
43
+ do_some_with_fixtures(fixtures) do |directory, fixture|
44
+ require directory/fixture
45
+ end
46
+ end
47
+
48
+ private
49
+ def do_some_with_fixtures(fixtures, &block)
50
+ fixtures.each do |fixture|
51
+ directory = Merb::Plugins.config[:fixtures][:directory]
52
+ fixture = "#{fixture}.rb"
53
+ block.call(directory, fixture)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,30 @@
1
+ # Get name of rake task
2
+ #
3
+ # ==== Parameters
4
+ # taskname<Symbol>::
5
+ # Name of task. For example :load.
6
+ # orm<Symbol>::
7
+ # Name of ORM. The ORM choosen in use_orm is used by default.
8
+ # Possibilities: :datamapper, :activerecord or :sequel
9
+ #
10
+ # ==== Example
11
+ # Merb::Fixtures::ORM.task(:load) => dm:db:fixtures:load # Default ORM was DataMapper
12
+ # Merb::Fixtures::ORM.task(:load, :sequel) => sequel:db:fixtures:load
13
+ #
14
+ # ==== Returns
15
+ # String:: Name of task. For example dm:db:fixtures:load
16
+ #
17
+ # @semipublic
18
+ def taskname(name)
19
+ case Merb.orm
20
+ when :datamapper : "dm:db:fixtures:#{name}"
21
+ when :sequel : "sequel:db:fixtures:#{name}"
22
+ when :activerecord : "db:fixtures:#{name}"
23
+ end
24
+ end
25
+
26
+ desc "Load the fixtures into database"
27
+ task taskname(:load) => :merb_env do
28
+ Merb::Fixtures.load
29
+ Merb::Fixtures.save
30
+ end
@@ -0,0 +1,43 @@
1
+ require "merb-fixtures/extensions/object_space"
2
+
3
+ module Merb
4
+ module Fixtures
5
+ module ORM
6
+ # Get array of model classes.
7
+ #
8
+ # ==== Parameters
9
+ # orm<Symbol>::
10
+ # Name of ORM. The ORM choosen in use_orm is used by default.
11
+ # Possibilities: :datamapper, :activerecord or :sequel
12
+ #
13
+ # ==== Returns
14
+ # Array[Class]:: Array of model classes.
15
+ #
16
+ # @semipublic
17
+ def self.models(orm = ::ORM)
18
+ models = Array.new
19
+ case orm
20
+ when :datamapper
21
+ ObjectSpace.each_class do |klass|
22
+ if klass.included_modules.include?(DataMapper::Resource)
23
+ models.push(klass)
24
+ end
25
+ end
26
+ when :sequel
27
+ ObjectSpace.each_class do |klass|
28
+ if klass < Sequel::Model
29
+ models.push(klass)
30
+ end
31
+ end
32
+ when :activerecord
33
+ ObjectSpace.each_class do |klass|
34
+ if klass < ActiveRecord::Base
35
+ models.push(klass)
36
+ end
37
+ end
38
+ end
39
+ return models
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1 @@
1
+ # ActiveRecord::Base.send(:include, Merb::Fixtures::Extensions)
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "merb-fixtures/datamapper"
3
+
4
+ # FIXME: MOVE TO EXTENSIONS
5
+ # Mock object
6
+ class Author
7
+ attr_reader :created_at
8
+ include DataMapper::Resource
9
+ def initialize
10
+ @created_at = Time.now
11
+ end
12
+ end
13
+
14
+ describe "<model>" do
15
+ before(:each) do
16
+ @botanicus = Author.new
17
+ @fixtures = Array(@botanicus)
18
+ Author.get_fixture.create(:botanicus, @botanicus)
19
+ end
20
+
21
+ describe ".fixture" do
22
+ it "should returns Fixture instance if no argument given" do
23
+ Author.fixture.should be_instance_of(Fixture)
24
+ end
25
+
26
+ it "should returns unique instance" do
27
+ one = Author.fixture(:botanicus)
28
+ two = Author.fixture(:botanicus)
29
+ one.object_id.should eql(two.object_id)
30
+ end
31
+
32
+ it "should returns fixture object if argument with its name is given" do
33
+ Author.fixture(:botanicus).should eql(@botanicus)
34
+ end
35
+ end
36
+
37
+ describe ".fixtures" do
38
+ it "should returns fixtures objects" do
39
+ Author.fixtures.should eql(@fixtures)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "merb-fixtures/fixture"
3
+
4
+ describe Fixture do
5
+ before(:each) do
6
+ @fixture = Fixture.new
7
+ @botanicus = mock("Botanicus")
8
+ end
9
+
10
+ it "should create new fixture" do
11
+ @fixture.create(:other_author, @botanicus)
12
+ @fixture.load(:other_author).should eql(@botanicus)
13
+ end
14
+
15
+ describe ".all" do
16
+ it "should returns array of each models which has one or more fixtures"
17
+ end
18
+
19
+ describe "#load" do
20
+ before(:each) do
21
+ @fixture.create(:botanicus, @botanicus)
22
+ end
23
+
24
+ it "should load existing fixture" do
25
+ @fixture.load(:botanicus).should eql(@botanicus)
26
+ end
27
+
28
+ it "should returns nil if fixture doesn't exist" do
29
+ @fixture.load(:non_existing_author).should be_nil
30
+ end
31
+ end
32
+
33
+ describe "#objects" do
34
+ before(:each) do
35
+ @another = mock("Another Author")
36
+ end
37
+
38
+ it "should returns empty array by default" do
39
+ @fixture.objects.should eql(Array.new)
40
+ end
41
+
42
+ # FIXME: sort problem
43
+ it "should return all instance's fixtures" do
44
+ @fixture.create(:botanicus, @botanicus)
45
+ @fixture.create(:another, @another)
46
+ @fixture.objects.should eql([@botanicus, @another])
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require "merb-fixtures/kernel"
3
+ require "merb-fixtures/fixture"
4
+
5
+ describe Kernel do
6
+ before(:each) do
7
+ @author = mock("Author")
8
+ @botanicus = mock("Botanicus")
9
+ @fixture = lambda { fixture_for(@author, :botanicus) }
10
+ @author.should_receive(:new).any_number_of_times.and_return(@botanicus)
11
+ @author.should_receive(:fixture).any_number_of_times.and_return(Fixture.new)
12
+ end
13
+
14
+ it "should returns model object" do
15
+ @fixture.call.should eql(@botanicus)
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ require "merb-fixtures/shared/orm"
3
+
4
+ describe Merb::Fixtures::ORM do
5
+ include SpecHelper
6
+ before(:all) do
7
+ models :datamapper, "Author", "Post"
8
+ models :activerecord, "Content", "User"
9
+ models :sequel, "Update", "Tag"
10
+ end
11
+
12
+ describe "::models" do
13
+ it "should returns all DataMapper models" do
14
+ Merb::Fixtures::ORM.models(:datamapper).should eql([Post, Author])
15
+ end
16
+
17
+ it "should returns all ActiveRecord models" do
18
+ Merb::Fixtures::ORM.models(:activerecord).should eql([User, Content])
19
+ end
20
+
21
+ it "should returns all Sequel models" do
22
+ Merb::Fixtures::ORM.models(:sequel).should eql([Tag, Update])
23
+ end
24
+ end
25
+
26
+ describe "::tasks" do
27
+ it "should returns correct name of DataMapper task" do
28
+ Merb::Fixtures::ORM.task(:load, :datamapper).should eql("dm:db:fixtures:load")
29
+ end
30
+
31
+ it "should returns correct name of ActiveRecord task" do
32
+ Merb::Fixtures::ORM.task(:load, :activerecord).should eql("db:fixtures:load")
33
+ end
34
+
35
+ it "should returns correct name of Sequel task" do
36
+ Merb::Fixtures::ORM.task(:load, :sequel).should eql("sequel:db:fixtures:load")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ $TESTING = true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ ORM = nil
5
+ module SpecHelper
6
+ # model "User", :activerecord
7
+ def model(orm = ORM, name = nil)
8
+ case orm
9
+ when :datamapper
10
+ require "merb_datamapper"
11
+ require "dm-core"
12
+ eval %{ class ::#{name} ; include ::DataMapper::Resource ; end }
13
+ when :activerecord
14
+ require "active_record"
15
+ require "merb_activerecord"
16
+ eval %{ class ::#{name} < ActiveRecord::Base ; end }
17
+ when :sequel
18
+ require "sequel"
19
+ require "merb_sequel"
20
+ eval %{ class ::#{name} < Sequel::Model ; end }
21
+ end
22
+ end
23
+
24
+ def models(orm, *names)
25
+ names.each do |name|
26
+ model orm, name
27
+ end
28
+ end
29
+ end
30
+
31
+ Spec::Runner.configure do |config|
32
+ config.mock_with :rspec
33
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb-fixtures-gogolok
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.5
5
+ platform: ruby
6
+ authors:
7
+ - !binary |
8
+ SmFrdWIgxaDFpWFzdG7DvQ==
9
+
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-11-16 00:00:00 +01:00
15
+ default_executable:
16
+ dependencies: []
17
+
18
+ description: Merb plugin that provides flexible fixtures system. DataMapper, ActiveRecord and Sequel is supported.
19
+ email: knava.bestvinensi@gmail.com
20
+ executables: []
21
+
22
+ extensions: []
23
+
24
+ extra_rdoc_files:
25
+ - README
26
+ - LICENSE
27
+ - TODO
28
+ files:
29
+ - LICENSE
30
+ - README
31
+ - Rakefile
32
+ - TODO
33
+ - lib/merb-fixtures.rb
34
+ - lib/merb-fixtures/activerecord/activerecord.rb
35
+ - lib/merb-fixtures/activerecord/merbtasks.rb
36
+ - lib/merb-fixtures/datamapper/datamapper.rb
37
+ - lib/merb-fixtures/datamapper/merbtasks.rb
38
+ - lib/merb-fixtures/extensions/object_space.rb
39
+ - lib/merb-fixtures/sequel/merbtasks.rb
40
+ - lib/merb-fixtures/sequel/sequel.rb
41
+ - lib/merb-fixtures/shared/exceptions.rb
42
+ - lib/merb-fixtures/shared/extensions.rb
43
+ - lib/merb-fixtures/shared/fixture.rb
44
+ - lib/merb-fixtures/shared/fixtures.rb
45
+ - lib/merb-fixtures/shared/helpers.rb
46
+ - lib/merb-fixtures/shared/kernel.rb
47
+ - lib/merb-fixtures/shared/merbtasks.rb
48
+ - lib/merb-fixtures/shared/orm.rb
49
+ - spec/merb-fixtures/activerecord/activerecord_spec.rb
50
+ - spec/merb-fixtures/datamapper/datamapper_spec.rb
51
+ - spec/merb-fixtures/extensions/object_space_spec.rb
52
+ - spec/merb-fixtures/sequel/sequel_spec.rb
53
+ - spec/merb-fixtures/shared/errors_spec.rb
54
+ - spec/merb-fixtures/shared/extensions_spec.rb
55
+ - spec/merb-fixtures/shared/fixture_spec.rb
56
+ - spec/merb-fixtures/shared/fixtures_spec.rb
57
+ - spec/merb-fixtures/shared/helpers_spec.rb
58
+ - spec/merb-fixtures/shared/kernel_spec.rb
59
+ - spec/merb-fixtures/shared/orm_spec.rb
60
+ - spec/spec_helper.rb
61
+ has_rdoc: true
62
+ homepage: http://botablog.cz/
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ requirements: []
83
+
84
+ rubyforge_project: merb
85
+ rubygems_version: 1.3.5
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Merb plugin that provides flexible fixtures system. DataMapper, ActiveRecord and Sequel is supported.
89
+ test_files: []
90
+