multisite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/multisite.rb +14 -0
- data/lib/multisite/default_scope_override.rb +13 -0
- data/lib/multisite/version.rb +3 -0
- data/multisite.gemspec +26 -0
- data/spec/lib/multisite/default_scope_override.rb +66 -0
- data/spec/lib/multisite_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- metadata +121 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.2@multisite
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/multisite.rb
ADDED
data/multisite.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "multisite/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "multisite"
|
7
|
+
s.version = Multisite::VERSION
|
8
|
+
s.authors = ["Josh Adams"]
|
9
|
+
s.email = ["josh@isotope11.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Make a naive rails app multisite easily}
|
12
|
+
|
13
|
+
s.rubyforge_project = "multisite"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency 'activerecord', '~> 3.1.0.rc4'
|
21
|
+
s.add_dependency 'activesupport', '~> 3.1.0.rc4'
|
22
|
+
|
23
|
+
s.add_development_dependency "sqlite3", "~> 1.3.3"
|
24
|
+
s.add_development_dependency 'rspec', '~> 2.6'
|
25
|
+
s.add_development_dependency 'ruby-debug19'
|
26
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_support'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
8
|
+
|
9
|
+
ActiveRecord::Base.connection.create_table(:widgets) do |t|
|
10
|
+
t.string :name
|
11
|
+
t.integer :site_id
|
12
|
+
end
|
13
|
+
|
14
|
+
ActiveRecord::Base.connection.create_table(:sites) do |t|
|
15
|
+
t.string :domain
|
16
|
+
end
|
17
|
+
|
18
|
+
class Widget < ActiveRecord::Base
|
19
|
+
belongs_to :site
|
20
|
+
|
21
|
+
include Multisite::DefaultScopeOverride
|
22
|
+
end
|
23
|
+
|
24
|
+
class Site < ActiveRecord::Base
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
describe Multisite::DefaultScopeOverride do
|
29
|
+
context "basic scope requirements" do
|
30
|
+
describe "querying without setting Multisite.current_site" do
|
31
|
+
it "should raise" do
|
32
|
+
lambda{ Widget.first }.should raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "querying with Multisite.current_site set" do
|
37
|
+
it "should not raise" do
|
38
|
+
Multisite.current_site = OpenStruct.new({:id => 1})
|
39
|
+
lambda{ Widget.first }.should_not raise_error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "scoping by site" do
|
45
|
+
before(:each) do
|
46
|
+
@site1 = Site.create(:domain => 'jd.com')
|
47
|
+
@site2 = Site.create(:domain => 'josh.com')
|
48
|
+
|
49
|
+
Multisite.current_site = @site1
|
50
|
+
@widget1 = Widget.create :name => 'jd widget'
|
51
|
+
|
52
|
+
Multisite.current_site = @site2
|
53
|
+
Widget.create :name => 'josh widget'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should find widgets in current site" do
|
57
|
+
Multisite.current_site = @site2
|
58
|
+
|
59
|
+
w = Widget.find_by_name 'jd widget'
|
60
|
+
w.should be_nil
|
61
|
+
|
62
|
+
w = Widget.find_by_name 'josh widget'
|
63
|
+
w.should_not be_nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'multisite'
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multisite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Adams
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-24 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: activerecord
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 3.1.0.rc4
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 3.1.0.rc4
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: sqlite3
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.3.3
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "2.6"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: ruby-debug19
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
description:
|
72
|
+
email:
|
73
|
+
- josh@isotope11.com
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files: []
|
79
|
+
|
80
|
+
files:
|
81
|
+
- .gitignore
|
82
|
+
- .rvmrc
|
83
|
+
- Gemfile
|
84
|
+
- Rakefile
|
85
|
+
- lib/multisite.rb
|
86
|
+
- lib/multisite/default_scope_override.rb
|
87
|
+
- lib/multisite/version.rb
|
88
|
+
- multisite.gemspec
|
89
|
+
- spec/lib/multisite/default_scope_override.rb
|
90
|
+
- spec/lib/multisite_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
has_rdoc: true
|
93
|
+
homepage: ""
|
94
|
+
licenses: []
|
95
|
+
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
requirements: []
|
114
|
+
|
115
|
+
rubyforge_project: multisite
|
116
|
+
rubygems_version: 1.6.2
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Make a naive rails app multisite easily
|
120
|
+
test_files: []
|
121
|
+
|