spec/ballast/concerns/view_spec.rb in ballast-1.9.3 vs spec/ballast/concerns/view_spec.rb in ballast-2.0.0
- old
+ new
@@ -6,15 +6,10 @@
require "spec_helper"
describe Ballast::Concerns::View do
class ViewMockClass < OpenStruct
include Ballast::Concerns::View
-
- def initialize(attrs)
- @operation = OpenStruct.new(attrs.delete(:operation))
- super(attrs)
- end
end
subject{ ViewMockClass.new(response: OpenStruct.new(headers: {}), headers: {}, params: {}, performed?: false) }
describe "#scope_css" do
@@ -25,115 +20,109 @@
end
end
describe "#browser" do
it "should return a browser object" do
- expect(subject).to receive(:request).and_return(OpenStruct.new(user_agent: "AGENT"))
- expect(Brauser::Browser).to receive(:new).with("AGENT").and_return("BROWSER")
+ expect(subject).to receive(:request).exactly(2).and_return(OpenStruct.new(user_agent: "AGENT", headers: {"Accept-Language" => "FOO"}))
+ expect(Brauser::Browser).to receive(:new).with("AGENT", "FOO").and_return("BROWSER")
expect(subject.browser).to eq("BROWSER")
end
end
describe "#browser_supported?" do
- before(:each) do
- expect(subject).to receive(:request).and_return(OpenStruct.new(user_agent: "AGENT"))
+ before(:example) do
+ expect(subject).to receive(:request).exactly(2).and_return(OpenStruct.new(user_agent: "AGENT", headers: {"Accept-Language" => "FOO"}))
end
it "should check if a browser is supported" do
- expect(subject.browser).to receive(:supported?).with("CONF").and_return("SUPPORTED")
+ expect(subject.browser).to receive(:supported?).with(Dir.pwd + "/CONF").and_return("SUPPORTED")
expect(subject.browser_supported?("CONF")).to eq("SUPPORTED")
end
it "should use a default file" do
- class Rails
- def self.root
- Pathname.new("ROOT")
- end
- end
-
- expect(subject.browser).to receive(:supported?).with("ROOT/config/supported-browsers.yml").and_return(true)
+ expect(subject.browser).to receive(:supported?).with(Dir.pwd + "/config/supported-browsers.yml").and_return(true)
subject.browser_supported?
end
end
describe "#layout_params" do
it "should return a single parameter" do
- subject.set_layout_params(a: 1)
+ subject.update_layout_params(a: 1)
expect(subject.layout_params(:a)).to eq(1)
end
it "should return a default value for a missing parameter" do
- subject.set_layout_params(a: 1)
+ subject.update_layout_params(a: 1)
expect(subject.layout_params(:b, 2)).to eq(2)
end
it "should never raise an error" do
expect(subject.layout_params(:a)).to be_nil
expect(subject.layout_params(:a, 3)).to eq(3)
end
it "should return the entire hash if no arguments are passed" do
expect(subject.layout_params).to eq({})
- subject.set_layout_params(a: 1)
+ subject.update_layout_params(a: 1)
expect(subject.layout_params).to eq({"a" => 1})
end
end
- describe "#set_layout_params" do
+ describe "#update_layout_params" do
it "should merge arguments into the existing parameters" do
expect(subject.layout_params).to eq({})
- subject.set_layout_params(a: 1, b: 2)
+ subject.update_layout_params(a: 1, b: 2)
expect(subject.layout_params).to eq({"a" => 1, "b" => 2})
end
end
describe "#javascript_params" do
- before(:each) do
+ before(:example) do
subject.instance_variable_set(:@javascript_params, {a: "1", b: 2})
end
it "should output Javascript as HTML" do
expect(subject).to receive(:content_tag).with(:tag, '{"a":"1","b":2}', {"data-jid" => "ID"}).and_return("HTML")
- expect(subject.javascript_params("ID", :tag)).to eq("HTML")
+ expect(subject.javascript_params("ID", tag: :tag)).to eq("HTML")
end
it "should return Javascript as Hash" do
expect(subject.javascript_params(false)).to eq({a: "1", b: 2})
expect(subject.javascript_params(nil)).to eq({a: "1", b: 2})
end
end
- describe "#add_javascript_params" do
- before(:each) do
- subject.add_javascript_params(:a, {b: 1})
+ describe "#update_javascript_params" do
+ before(:example) do
+ subject.update_javascript_params(:a, {b: 1})
end
it "should create an Hash" do
expect(subject.instance_variable_get(:@javascript_params)).to be_a(HashWithIndifferentAccess)
end
it "should add new keys" do
- subject.add_javascript_params(:c, {d: 2})
+ subject.update_javascript_params(:c, {d: 2})
expect(subject.instance_variable_get(:@javascript_params)).to eq({a: {b: 1}, c: {d: 2}}.with_indifferent_access)
end
it "should merge values for the same key" do
- subject.add_javascript_params(:a, {d: 2})
+ subject.update_javascript_params(:a, {d: 2})
expect(subject.instance_variable_get(:@javascript_params)).to eq({a: {b: 1, d: 2}}.with_indifferent_access)
end
it "should replace values for same key if requested to" do
- subject.add_javascript_params(:a, {d: 2}, true)
+ subject.update_javascript_params(:a, {d: 2}, replace: true)
expect(subject.instance_variable_get(:@javascript_params)).to eq({a: {d: 2}}.with_indifferent_access)
end
it "should merge from the root" do
- subject.add_javascript_params(nil, {d: 2})
+ subject.update_javascript_params(nil, {d: 2})
expect(subject.instance_variable_get(:@javascript_params)).to eq({a: {b: 1}, d: 2}.with_indifferent_access)
end
it "should replace the entire hash" do
- subject.add_javascript_params(nil, {d: 2}, true)
+ subject.update_javascript_params(nil, {d: 2}, replace: true)
expect(subject.instance_variable_get(:@javascript_params)).to eq({d: 2}.with_indifferent_access)
end
end
end
\ No newline at end of file