|
2 | 2 | require 'gon' |
3 | 3 |
|
4 | 4 | describe Gon, '#all_variables' do |
5 | | - before(:each) do |
| 5 | + |
| 6 | + before(:each) do |
6 | 7 | Gon.request_env = {} |
7 | 8 | end |
8 | 9 |
|
|
49 | 50 | Gon.objects.length.should == 2 |
50 | 51 | end |
51 | 52 |
|
52 | | - it 'render json from jbuilder template' do |
53 | | - Gon.clear |
54 | | - controller = ActionController::Base.new |
55 | | - objects = [1,2] |
56 | | - controller.instance_variable_set('@objects', objects) |
57 | | - Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller |
58 | | - Gon.objects.length.should == 2 |
59 | | - end |
| 53 | + if RUBY_VERSION =~ /1.9/ |
| 54 | + require 'jbuilder' |
| 55 | + require 'gon/jbuilder' |
60 | 56 |
|
61 | | - it 'render json from jbuilder template with a partial' do |
62 | | - Gon.clear |
63 | | - controller = ActionController::Base.new |
64 | | - controller.view_paths << 'spec/test_data' |
65 | | - objects = [1,2] |
66 | | - controller.instance_variable_set('@objects', objects) |
67 | | - Gon.jbuilder 'spec/test_data/sample_with_partial.json.jbuilder', :controller => controller |
68 | | - Gon.objects.length.should == 2 |
| 57 | + it 'render json from jbuilder template' do |
| 58 | + Gon.clear |
| 59 | + controller = ActionController::Base.new |
| 60 | + objects = [1,2] |
| 61 | + controller.instance_variable_set('@objects', objects) |
| 62 | + Gon.jbuilder 'spec/test_data/sample.json.jbuilder', :controller => controller |
| 63 | + Gon.objects.length.should == 2 |
| 64 | + end |
| 65 | + |
| 66 | + it 'render json from jbuilder template with a partial' do |
| 67 | + Gon.clear |
| 68 | + controller = ActionController::Base.new |
| 69 | + controller.view_paths << 'spec/test_data' |
| 70 | + objects = [1,2] |
| 71 | + controller.instance_variable_set('@objects', objects) |
| 72 | + Gon.jbuilder 'spec/test_data/sample_with_partial.json.jbuilder', :controller => controller |
| 73 | + Gon.objects.length.should == 2 |
| 74 | + end |
| 75 | + |
| 76 | + it 'should throw error if you use gon.jbuilder with ruby < 1.9+' do |
| 77 | + RUBY_VERSION = '1.8.7' |
| 78 | + |
| 79 | + expect { Gon.jbuilder 'some_path' }.to raise_error(NoMethodError, /1.9/) |
| 80 | + end |
| 81 | + |
| 82 | + it 'should raise error if you use gon.jbuilder without requairing jbuilder gem' do |
| 83 | + RUBY_VERSION = '1.9.2' |
| 84 | + Gon.send(:remove_const, :Jbuilder) |
| 85 | + |
| 86 | + expect { Gon.jbuilder 'some_path' }.to raise_error(NoMethodError, /Gemfile/) |
| 87 | + end |
69 | 88 | end |
70 | 89 |
|
71 | 90 | def request |
72 | 91 | @request ||= double 'request', :env => {} |
73 | 92 | end |
| 93 | + |
74 | 94 | end |
0 commit comments