This repository has been archived by the owner on Dec 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7f0c77
commit f776eda
Showing
3 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
spec/timber/contexts/organizations/action_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require "spec_helper" | ||
|
||
describe Timber::Contexts::Organizations::ActionController do | ||
around(:each) do |example| | ||
class PagesController < ActionController::Base | ||
layout nil | ||
|
||
def index | ||
render json: {} | ||
end | ||
|
||
def method_for_action(action_name) | ||
action_name | ||
end | ||
|
||
private | ||
def current_organization | ||
# I want this to execute a query and test logging that query | ||
Organization.first | ||
end | ||
end | ||
|
||
example.run | ||
|
||
Object.send(:remove_const, :PagesController) | ||
end | ||
|
||
let(:context) { described_class.new(PagesController.new) } | ||
|
||
describe "#name" do | ||
subject { context.name } | ||
it { should be_nil } | ||
|
||
context "with an organization" do | ||
before(:each) { Organization.create!(name: "Timber") } | ||
it { should eq("Timber") } | ||
|
||
context "with an organization context" do | ||
around(:each) do |example| | ||
Timber::CurrentContext.add(context) do | ||
example.run | ||
end | ||
end | ||
|
||
it { should eq("Timber") } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require "spec_helper" | ||
|
||
describe Timber::Contexts::Users::ActionController do | ||
around(:each) do |example| | ||
class PagesController < ActionController::Base | ||
layout nil | ||
|
||
def index | ||
render json: {} | ||
end | ||
|
||
def method_for_action(action_name) | ||
action_name | ||
end | ||
|
||
private | ||
def current_user | ||
# I want this to execute a query and test logging that query | ||
@user ||= User.first | ||
end | ||
end | ||
|
||
example.run | ||
|
||
Object.send(:remove_const, :PagesController) | ||
|
||
Timber::Probes::ActiveSupportLogSubscriber.insert! | ||
end | ||
|
||
let(:context) { described_class.new(PagesController.new) } | ||
|
||
describe "#email" do | ||
subject { context.email } | ||
it { should be_nil } | ||
|
||
context "with a user" do | ||
before(:each) { User.create!(email: "a@a.com") } | ||
it { should eq("a@a.com") } | ||
|
||
context "with a user context" do | ||
around(:each) do |example| | ||
Timber::CurrentContext.add(context) do | ||
example.run | ||
end | ||
end | ||
|
||
it { should eq("a@a.com") } | ||
|
||
context "with a debug log level" do | ||
around(:each) do |example| | ||
old_level = ::Rails.logger.level | ||
::Rails.logger.level = ::Logger::DEBUG | ||
example.run | ||
::Rails.logger.level = old_level | ||
end | ||
|
||
# If the user object is not cached, it will create an infinite loop. | ||
# This is because getting the user executes a query, which in turn creates | ||
# logs, with tries to grab the user again, etc. | ||
it { should eq("a@a.com") } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters