diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index a60806d..66d2a1f 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -26,7 +26,8 @@ def create
@category = authorize Category.new(category_params)
if @category.save
- redirect_to @category, notice: 'Category was successfully created.'
+ redirect_to category_url(@category, subdomain: current_tenant.subdomain),
+ notice: 'Category was successfully created.'
else
render :new
end
@@ -37,7 +38,8 @@ def update
authorize @category
if @category.update(category_params)
- redirect_to @category, notice: 'Category was successfully updated.'
+ redirect_to category_url(@category, subdomain: current_tenant.subdomain),
+ notice: 'Category was successfully updated.'
else
render :edit
end
@@ -48,7 +50,7 @@ def destroy
authorize @category
if @category.destroy
- redirect_to categories_url, alert: 'Category was successfully destroyed.'
+ redirect_to categories_url(subdomain: current_tenant.subdomain), alert: 'Category was successfully destroyed.'
end
end
diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
index 55a7430..e5fa7ef 100644
--- a/app/controllers/home_controller.rb
+++ b/app/controllers/home_controller.rb
@@ -4,6 +4,7 @@ class HomeController < ApplicationController
skip_before_action :authenticate_user!, :redirect_notenant
def index
+ @domain = [request.subdomains.last, request.domain].reject(&:blank?).join('.')
@organizations = Organization.nonadmin.order(:name)
end
end
diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb
index aec5e66..91c7dee 100644
--- a/app/views/home/index.html.erb
+++ b/app/views/home/index.html.erb
@@ -2,6 +2,6 @@ Welcome to Babywearing. Please click the link to one of our sites below:
<% @organizations.each do |org| %>
- - <%= link_to org.name, root_url(subdomain: org.subdomain) %>
+ - <%= link_to org.name, root_url(domain: @domain, subdomain: org.subdomain) %>
<% end %>
diff --git a/config/environments/development.rb b/config/environments/development.rb
index 739aaab..74720ed 100644
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -63,5 +63,5 @@
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: 'mailcatcher', port: 1025 }
- config.hosts << "midatlantic.lvh.me" << "acme.lvh.me" << "admin.lvh.me" << "lvh.me" << "midatlantic.stage.lvh.me"
+ config.hosts << /^([a-zA-Z0-9]*\.)*(lvh\.me|babywearing\.exchange)$/
end
diff --git a/config/routes.rb b/config/routes.rb
index 40ca6ae..ce34293 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -28,7 +28,7 @@
resources :photos, only: :destroy
- constraints subdomain: "admin" do
+ constraints subdomain: %w(admin admin.stage) do
root :to => "categories#index", :as=> :subdomain_root
resources :categories
end
diff --git a/deploy/deploy_hash b/deploy/deploy_hash
index b3a4252..48cdce8 100644
--- a/deploy/deploy_hash
+++ b/deploy/deploy_hash
@@ -1 +1 @@
-placeholder
\ No newline at end of file
+placeholder
diff --git a/spec/features/category_spec.rb b/spec/features/category_spec.rb
index 18a3574..6158a3c 100644
--- a/spec/features/category_spec.rb
+++ b/spec/features/category_spec.rb
@@ -11,7 +11,7 @@
end
it "allows user to create a category" do
- visit categories_url
+ visit categories_url(subdomain: "admin")
find_link("+ New").click
fill_in "Name", with: "pineapple"
fill_in "Description", with: "sweet"
@@ -22,7 +22,7 @@
end
it "allows user to update a category" do
- visit categories_url
+ visit categories_url(subdomain: "admin")
click_link category.name
expect(page).to have_content category.name
find_link("Edit").click
@@ -33,14 +33,14 @@
end
it "allows user to delete a category" do
- visit categories_url
+ visit categories_url(subdomain: "admin")
expect(page).to have_content category.name
find_link("Destroy").click
expect(page).to have_content "Category was successfully destroyed."
end
it 'expands the subcategories table' do
- visit(categories_url)
+ visit(categories_url(subdomain: "admin"))
expect(page).to have_content(category.name)
expect(page).not_to have_content(category_child.name)
find_link('+').click
diff --git a/spec/requests/application_spec.rb b/spec/requests/application_spec.rb
index 6f385cc..8d97a6e 100644
--- a/spec/requests/application_spec.rb
+++ b/spec/requests/application_spec.rb
@@ -30,4 +30,14 @@
expect(response).to redirect_to(new_user_session_url)
end
end
+
+ describe "admin organization redirect" do
+ context "with no session" do
+ it "redirects to sign in" do
+ get root_url(domain: "stage.example.com", subdomain: "admin")
+
+ expect(response).to redirect_to(new_user_session_url)
+ end
+ end
+ end
end
diff --git a/spec/requests/categories_spec.rb b/spec/requests/categories_spec.rb
index 4697a45..0bac301 100644
--- a/spec/requests/categories_spec.rb
+++ b/spec/requests/categories_spec.rb
@@ -5,95 +5,91 @@
RSpec.describe "Categories", type: :request do
let!(:category) { categories(:category_parent) }
- within_subdomain("admin") do
- describe 'GET /categories' do
- it 'has http status 200' do
- sign_in users(:admin_org)
- get categories_url
+ describe 'GET /categories' do
+ it 'has http status 200' do
+ sign_in users(:admin_org)
+ get categories_url(subdomain: "admin")
- expect(response).to be_successful
- expect(response.body).to match(/category parent/)
- end
+ expect(response).to be_successful
+ expect(response.body).to match(/category parent/)
end
+ end
- describe 'POST /categories' do
- let(:valid_attr) { { name: 'Test', description: 'Test content' } }
- let(:invalid_attr) { { name: '' } }
+ describe 'POST /categories' do
+ let(:valid_attr) { { name: 'Test', description: 'Test content' } }
+ let(:invalid_attr) { { name: '' } }
- context 'with valid attributes' do
- it 'creates a category' do
- sign_in users(:admin_org)
- post categories_url, params: { category: valid_attr }
+ context 'with valid attributes' do
+ it 'creates a category' do
+ sign_in users(:admin_org)
+ post categories_url(subdomain: "admin"), params: { category: valid_attr }
- expect(response).to redirect_to(category_url(assigns(:category)))
- expect(flash[:notice]).to eq('Category was successfully created.')
- end
+ expect(response).to redirect_to(category_url(assigns(:category), subdomain: "admin"))
+ expect(flash[:notice]).to eq('Category was successfully created.')
end
+ end
- context 'with invalid attributes' do
- it "doen't create a category" do
- sign_in users(:admin_org)
- send :post, categories_url, params: { category: invalid_attr }
+ context 'with invalid attributes' do
+ it "doesn't create a category" do
+ sign_in users(:admin_org)
+ send :post, categories_url(subdomain: "admin"), params: { category: invalid_attr }
- expect(response.body).to match(/prohibited this/)
- end
+ expect(response.body).to match(/prohibited this/)
end
end
+ end
- describe 'GET /categories/:id' do
- it 'has have_http_status 200' do
- sign_in users(:admin_org)
- get categories_url(category)
+ describe 'GET /categories/:id' do
+ it 'has have_http_status 200' do
+ sign_in users(:admin_org)
+ get categories_url(category, subdomain: "admin")
- expect(response).to be_successful
- expect(response.body).to match(/category parent/)
- end
+ expect(response).to be_successful
+ expect(response.body).to match(/category parent/)
end
+ end
- describe 'PUT /category/:id' do
- let(:valid_attr) { { name: 'New agreement', description: 'New content' } }
- let(:invalid_attr) { { name: '' } }
+ describe 'PUT /category/:id' do
+ let(:valid_attr) { { name: 'New category', description: 'New content' } }
+ let(:invalid_attr) { { name: '' } }
- context 'with valid attributes' do
- it 'updates the category' do
- sign_in users(:admin_org)
- send :put, category_url(category), params: { category: valid_attr }
+ context 'with valid attributes' do
+ it 'updates the category' do
+ sign_in users(:admin_org)
+ put category_url(category, subdomain: "admin"), params: { category: valid_attr }
- expect(flash[:notice]).to eq('Category was successfully updated.')
- end
+ expect(flash[:notice]).to eq('Category was successfully updated.')
end
+ end
- context 'with invalid attributes' do
- it "doesn't update the category" do
- sign_in users(:admin_org)
- send :put, category_url(category), params: { category: invalid_attr }
+ context 'with invalid attributes' do
+ it "doesn't update the category" do
+ sign_in users(:admin_org)
+ put category_url(category, subdomain: "admin"), params: { category: invalid_attr }
- expect(response.body).to match(/prohibited this/)
- end
+ expect(response.body).to match(/prohibited this/)
end
end
+ end
- describe 'DELETE /category/:id' do
- let(:category) { Category.create(name: 'Test', description: 'Test') }
+ describe 'DELETE /category/:id' do
+ let(:category) { Category.create(name: 'Test', description: 'Test') }
- it 'destroys the category' do
- sign_in users(:admin_org)
- send :delete, category_url(category)
+ it 'destroys the category' do
+ sign_in users(:admin_org)
+ delete category_url(category, subdomain: "admin")
- expect(response).to have_http_status(:found)
- expect(flash[:alert]).to eq('Category was successfully destroyed.')
- end
+ expect(response).to have_http_status(:found)
+ expect(flash[:alert]).to eq('Category was successfully destroyed.')
end
end
- within_subdomain("midatlantic") do
- describe 'GET /categories' do
- it 'has a routing error' do
- sign_in users(:member)
- expect do
- get "http://midatlantic.example.com/categories"
- end.to raise_error(ActionController::RoutingError)
- end
+ describe 'GET /categories' do
+ it 'has a routing error' do
+ sign_in users(:member)
+ expect do
+ get "http://midatlantic.example.com/categories"
+ end.to raise_error(ActionController::RoutingError)
end
end
end