test/unit/controllers/evercookie_controller_test.rb in evercookie-0.0.5 vs test/unit/controllers/evercookie_controller_test.rb in evercookie-0.0.6
- old
+ new
@@ -33,51 +33,51 @@
end
test "should set view variables on evercookie set and have right js" do
@controller = Evercookie::EvercookieController.new
- session[Evercookie.hash_name_for_set] = {key: 'testkey', value: 'testvalue'}
+ session_data = {key: 'testkey', value: 'testvalue'}
+ @request.session[Evercookie.hash_name_for_set] = session_data
get :set, format: :js
+
assert_response :success
- assert_equal assigns[:data], {'key' => 'testkey', 'value' => 'testvalue'}
+ assert_equal session_data, assigns(:data).symbolize_keys
assert @response.body.include? "var ec = new evercookie()"
assert @response.body.include? "ec.set('testkey', 'testvalue')"
end
test "should set view variables on evercookie get and have right js" do
@controller = Evercookie::EvercookieController.new
- session[Evercookie.hash_name_for_get] = {key: 'testkey'}
-
+ session_data = {key: 'testkey'}
+ @request.session[Evercookie.hash_name_for_get] = session_data
get :get, format: :js
assert_response :success
- assert_equal assigns[:data], {'key' => 'testkey'}
+ assert_equal session_data, assigns(:data).symbolize_keys
assert @response.body.include? "var ec = new evercookie()"
assert @response.body.include? "ec.get('testkey')"
end
test "should set session variables on evercookie save if cookie present" do
@controller = Evercookie::EvercookieController.new
- session[Evercookie.hash_name_for_get] = {key: 'testkey'}
- cookies[:testkey] = 'testvalue'
-
+ @request.cookies[:testkey] = 'testvalue'
+ @request.session[Evercookie.hash_name_for_get] = {key: 'testkey'}
get :save
assert_response :success
- assert_equal session[Evercookie.hash_name_for_saved],
- {'testkey' => 'testvalue'}
+ assert_equal 'testvalue', session[Evercookie.hash_name_for_saved]['testkey']
end
test "should not set session variables on save if cookie not present" do
@controller = Evercookie::EvercookieController.new
- session[Evercookie.hash_name_for_get] = {key: 'testkey'}
+ @request.session[Evercookie.hash_name_for_get] = {key: 'testkey'}
get :save
assert_response :success
assert session[Evercookie.hash_name_for_saved].nil?