Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Commit

Permalink
Namespaced models can now be used with Forem#user_class.
Browse files Browse the repository at this point in the history
  • Loading branch information
parndt committed Nov 24, 2012
1 parent 4efa137 commit 5112558
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/forem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def user_class
raise "You can no longer set Forem.user_class to be a class. Please use a string instead.\n\n " +
"See https://github.com/radar/forem/issues/88 for more information."
elsif @@user_class.is_a?(String)
Object.const_get(@@user_class)
begin
Object.const_get(@@user_class)
rescue NameError
@@user_class.constantize
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Refunery
class Yooser < ActiveRecord::Base

end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateRefuneryYoosers < ActiveRecord::Migration
create_table :refunery_yoosers, :force => true do |t|
t.string :name, :default => "", :null => false
t.string :email, :default => "", :null => false
end

add_index :refunery_yoosers, :email, :unique => true
end
46 changes: 46 additions & 0 deletions spec/models/refunery_yooser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

# There is no User class within Forem; this is testing the dummy application's class
# More specifically, it is testing the methods provided by Forem::DefaultPermissions
#
# Regression test for #329 and #335

describe Refunery::Yooser do

before(:each) do
@original_class_name = Forem.user_class
Forem.user_class = "Refunery::Yooser"
end

after(:each) do
Forem.user_class = @original_class_name.to_s
end

context "Without top level reference" do
before(:each) do
Forem.user_class = "Refunery::Yooser"
end

it "return class constant" do
assert_equal Refunery::Yooser, Forem.user_class
end

it "it return class as string" do
assert_equal "Refunery::Yooser", Forem.user_class.to_s
end
end

context "With top level reference" do
before(:each) do
Forem.user_class = "Refunery::Yooser"
end

it "return class constant" do
assert_equal Refunery::Yooser, Forem.user_class
end

it "it return class as string" do
assert_equal "Refunery::Yooser", Forem.user_class.to_s
end
end
end

0 comments on commit 5112558

Please sign in to comment.