@@ -364,7 +364,7 @@ def to_params
364364 end
365365 end
366366
367- context 'parsing an association of a class in a module'
367+ context 'parsing an association of a class in a module' do
368368 before do
369369 Her ::API . setup :url => "https://api.example.com" , :send_only_modified_attributes => true do |builder |
370370 builder . use Her ::Middleware ::FirstLevelParseJSON
@@ -382,4 +382,36 @@ def to_params
382382 it 'should not raise an error while trying to parse to params' do
383383 expect { subject . to_params } . to_not raise_error
384384 end
385+ end
386+
387+ describe "removing belongs_to associations" do
388+ before do
389+ Her ::API . setup :url => "https://api.example.com" do |builder |
390+ builder . use Her ::Middleware ::DefaultParseJSON
391+ builder . use Faraday ::Request ::UrlEncoded
392+ end
393+
394+ Her ::API . default_api . connection . adapter :test do |stub |
395+ stub . get ( "/users/1" ) { |env | [ 200 , { } , { :id => 1 , :first_name => "Tobias" , :last_name => "Fünke" , :family_id => 1 } . to_json ] }
396+ stub . get ( "/families/1" ) { |env | [ 200 , { } , { :id => 1 , :name => "Fünke" } . to_json ] }
397+ stub . get ( "/families/1/users" ) { |env | [ 200 , { } , [ { :id => 1 , :first_name => "Tobias" , :last_name => "Fünke" , :family_id => 1 } ] . to_json ] }
398+ end
399+
400+ spawn_model "User" do
401+ belongs_to :family
402+ end
403+
404+ spawn_model "Family" do
405+ has_many :users
406+ end
407+ end
408+
409+ it "should not include belongs_to relations" do
410+ family = Family . find ( 1 )
411+ family_user = family . users . first
412+ expect ( family_user . to_params [ :family ] ) . to be_blank
413+ end
414+
415+ end
416+
385417end
0 commit comments