Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added tests for the browser detector view helpers.

  • Loading branch information...
commit e18435a8bab61095d0ddaa242782c2504a9355cc 1 parent 8d45fc3
@midas authored
Showing with 102 additions and 10 deletions.
  1. +84 −10 test/guilded/rails/view_helpers_test.rb
  2. +18 −0 test/test_helper.rb
View
94 test/guilded/rails/view_helpers_test.rb
@@ -4,20 +4,94 @@ class ViewHelpersTest < Test::Unit::TestCase
context "The browser detector view helpers" do
setup do
- @view = ViewProxy.new
+ @view = View.new
end
- #should "output the correct browser name" do
- # assert @view.browser_name == ''
- #end
+ should "resolve the correct browser name" do
+ assert_equal 'firefox', @view.g_browser_name
+ end
+
+ should "resolve the correct g_browser_version" do
+ assert_equal '3.5.3', @view.g_browser_version
+ end
+
+ should "resolve the correct g_browser_full_name" do
+ assert_equal 'Firefox 3.5.3', @view.g_browser_full_name
+ end
+
+ should "resolve the correct g_browser_version" do
+ assert_equal '3.5.3', @view.g_browser_version
+ end
+
+ should "agree that the browser is :name => :firefox" do
+ assert @view.g_browser_is?( :name => :firefox )
+ end
+
+ should "agree that the browser is :version => '3.5.3'" do
+ assert @view.g_browser_is?( :version => '3.5.3' )
+ end
+
+ should "agree that the browser is :name => :firefox, :version => '3.5.3'" do
+ assert @view.g_browser_is?( :name => :firefox, :version => '3.5.3' )
+ end
+
+ should "agree that the browser is :name => :firefox, :major_version => '3'" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => '3' )
+ end
+
+ should "agree that the browser is :name => :firefox, :minor_version => '5'" do
+ assert @view.g_browser_is?( :name => :firefox, :minor_version => '5' )
+ end
+
+ should "agree that the browser is :name => :firefox, :build_version => '3'" do
+ assert @view.g_browser_is?( :name => :firefox, :build_version => '3' )
+ end
+
+ should "agree that the browser is :name => :firefox, :revision_version => '0'" do
+ assert @view.g_browser_is?( :name => :firefox, :revision_version => '0' )
+ end
+
+ should "agree that the browser is :name => :firefox, :major_version => '3', :minor_version => '5'" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => '3', :minor_version => '5' )
+ end
+
+ should "agree that the browser is :name => :firefox, :major_version => '3', :minor_version => '5', :build_version => '3'" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => '3', :minor_version => '5', :build_version => '3' )
+ end
+
+ should "agree that the browser is :name => :firefox, :major_version => '3', :minor_version => '5', :build_version => '3', :revision_version => '0'" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => '3', :minor_version => '5', :build_version => '3',
+ :revision_version => '0' )
+ end
+
+ should "agree that the browser is :name => :firefox, :major_version => 3" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => 3 )
+ end
+
+ should "agree that the browser is :name => :firefox, :minor_version => 5" do
+ assert @view.g_browser_is?( :name => :firefox, :minor_version => 5 )
+ end
+
+ should "agree that the browser is :name => :firefox, :build_version => 3" do
+ assert @view.g_browser_is?( :name => :firefox, :build_version => 3 )
+ end
+
+ should "agree that the browser is :name => :firefox, :revision_version => 0" do
+ assert @view.g_browser_is?( :name => :firefox, :revision_version => 0 )
+ end
- should "be true" do
- assert true
+ should "agree that the browser is :name => :firefox, :major_version => 3, :minor_version => 5" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => 3, :minor_version => 5 )
+ end
+
+ should "agree that the browser is :name => :firefox, :major_version => 3, :minor_version => 5, :build_version => 3" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => 3, :minor_version => 5, :build_version => 3 )
+ end
+
+ should "agree that the browser is :name => :firefox, :major_version => 3, :minor_version => 5, :build_version => 3, :revision_version => 0" do
+ assert @view.g_browser_is?( :name => :firefox, :major_version => 3, :minor_version => 5, :build_version => 3,
+ :revision_version => '0' )
end
end
-end
-
-class ViewProxy
- include Guilded::Rails::ViewHelpers
end
View
18 test/test_helper.rb
@@ -1,6 +1,7 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
+require 'mocha'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -28,3 +29,20 @@ class Parent
end
class Lookup
end
+
+class View
+ attr_accessor :request
+
+ def initialize
+ @request = Request.new
+ end
+end
+View.send( :include, Guilded::Rails::ViewHelpers )
+
+class Request
+ attr_accessor :env
+
+ def initialize
+ @env = { 'HTTP_USER_AGENT' => Guilded::BrowserDetector.user_agents[:firefox35] }
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.