require 'helper' describe Bearcat::Client::Sections do before do @client = Bearcat::Client.new(prefix:"http://canvas.instructure.com", token: "test_token") end it "returns all sections for a course" do stub_get(@client, "/api/v1/courses/3/sections").to_return(json_response("course_sections.json")) sections = @client.course_sections(3) sections.first['name'].should == 'test' sections.first['id'].should == 70 sections.first['course_id'].should == 3 end it "returns a section" do stub_get(@client, "/api/v1/sections/72").to_return(json_response("section.json")) section = @client.section(72) section['name'].should == 'Section003' section['id'].should == 72 section['course_id'].should == 3 end it "creates a section" do stub_post(@client, "/api/v1/courses/3/sections"). with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("create_section.json")) section = @client.create_section(3, {"course_section[name]" => "Section003"}) section['course_id'].should == 3 section['id'].should == 72 section['name'].should == 'Section003' end it "updates a section" do stub_put(@client, "/api/v1/sections/72").with(:body => {"course_section"=>{"name"=>"Section003"}}).to_return(json_response("update_section.json")) section = @client.update_section(72, {"course_section[name]" => "Section003"}) section['course_id'].should == 3 section['id'].should == 72 section['name'].should == 'Section003' end it "deletes a section" do stub_delete(@client, "/api/v1/sections/72").to_return(json_response("update_section.json")) section = @client.delete_section(72) section['course_id'].should == 3 section['id'].should == 72 section['name'].should == 'Section003' end it "crosslist a section" do stub_post(@client, "/api/v1/sections/72/crosslist/2").to_return(json_response("update_section.json")) section = @client.crosslist_section(72, 2) section['nonxlist_course_id'].should == 2 end it "de-crosslist a section" do stub_delete(@client, "/api/v1/sections/72/crosslist").to_return(json_response("update_section.json")) section = @client.decrosslist_section(72) section['nonxlist_course_id'].should == 2 end end