Skip to content
Browse files

adding a Rakefile for testing, proper extending(not including) of mod…

…ules, test that actually work and are correct
  • Loading branch information...
1 parent a8007f6 commit 6482e51bb59cca34857452c14a2cd336061ac007 @taelor taelor committed
View
42 Rakefile
@@ -0,0 +1,42 @@
+begin
+ require "bundler"
+ Bundler.setup
+rescue LoadError
+ $stderr.puts "You need to have Bundler installed to be able build this gem."
+end
+require "rake/testtask"
+
+gemspec = eval(File.read(Dir["*.gemspec"].first))
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the acts_as_restricted gem.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc "Validate the gemspec"
+task :gemspec do
+ gemspec.validate
+end
+
+desc "Build gem locally"
+task :build => :gemspec do
+ system "gem build #{gemspec.name}.gemspec"
+ FileUtils.mkdir_p "pkg"
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "pkg"
+end
+
+desc "Install gem locally"
+task :install => :build do
+ system "gem install pkg/#{gemspec.name}-#{gemspec.version}"
+end
+
+desc "Clean automatically generated files"
+task :clean do
+ FileUtils.rm_rf "pkg"
+end
View
4 acts_as_restricted_subdomain.gemspec
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
s.summary = 'Acts As Restricted Subdomain'
s.description = 'Instead of destroying active record objects, mark a column as deleted with a timestamp'
s.homepage = 'https://redmine.consoloservices.com'
- s.require_path = '.'
s.files = `git ls-files`.split("\n")
- s.add_dependency 'activerecord', '~> 3.0'
+ s.add_dependency 'activerecord', '~> 3.0'
+ s.add_dependency "activesupport", "~>3.0"
s.add_dependency 'actionpack', '~> 3.0'
end
View
2 lib/restricted_subdomain_controller.rb
@@ -136,4 +136,4 @@ def session=(*args)
end
end
-ActionController::Base.send :include, RestrictedSubdomain::Controller
+ActionController::Base.send :extend, RestrictedSubdomain::Controller
View
2 lib/restricted_subdomain_model.rb
@@ -182,4 +182,4 @@ def find_every(options)
end
end
-ActiveRecord::Base.send :include, RestrictedSubdomain::Model
+ActiveRecord::Base.send :extend, RestrictedSubdomain::Model
View
51 test/acts_as_restricted_subdomain_test.rb
@@ -1,19 +1,20 @@
require 'rubygems'
require 'test/unit'
require 'active_record'
+require "active_support"
require 'active_model'
$:.unshift "#{File.dirname(__FILE__)}/../"
$:.unshift "#{File.dirname(__FILE__)}/../lib/"
-require 'init'
+require 'restricted_subdomain_controller'
+require 'restricted_subdomain_model'
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
def setup_db
ActiveRecord::Schema.define(:version => 1) do
create_table :agencies do |t|
- t.string :name
t.string :code
t.timestamps
end
@@ -41,7 +42,7 @@ def to_s
class Thing < ActiveRecord::Base
- acts_as_restricted_subdomains
+ acts_as_restricted_subdomain
end
@@ -56,17 +57,24 @@ def assert_empty(collection)
def setup
setup_db
-
- ["agency_1", "agency_2", "agency_3"].each do |code|
- Agency.create! :code => code
- end
-
- Thing.create! :agency_1
- Thing.create! :agency_2
- Thing.create! :agency_2
- Thing.create! :agency_3
- Thing.create! :agency_3
- Thing.create! :agency_3
+
+ agency_1 = Agency.create! :code => "agency_1"
+ agency_2 = Agency.create! :code => "agency_2"
+ agency_3 = Agency.create! :code => "agency_3"
+
+ Agency.current = "agency_1"
+ Thing.create!
+
+ Agency.current = "agency_2"
+ Thing.create!
+ Thing.create!
+
+ Agency.current = "agency_3"
+ Thing.create!
+ Thing.create!
+ Thing.create!
+
+ Agency.current = nil
end
def teardown
@@ -77,17 +85,24 @@ def teardown
class AgencyTest < ActsAsRestrictedSubdomainBaseTest
def test_agency_current
Agency.current = "agency_1"
- assert_equal Agency.current, "agency_1"
+ assert_equal Agency.current.code, "agency_1"
end
end
class ThingTest < ActsAsRestrictedSubdomainBaseTest
- def test_real_removal
+ def test_unset_agency_count
+ Agency.current = nil
assert_equal 6, Thing.count
-
+ end
+
+ def test_set_agency_count
Agency.current = "agency_3"
assert_equal 3, Thing.count
- assert_equal Agency.current.id, Agency.all.collect(&:agency_id).uniq
+ end
+
+ def test_set_agency_find_all
+ Agency.current = "agency_3"
+ assert_equal [Agency.current.id], Thing.all.collect(&:agency_id).uniq
end
end

0 comments on commit 6482e51

Please sign in to comment.
Something went wrong with that request. Please try again.