diff options
Diffstat (limited to 'spec/controllers/api/v1/tutorials_controller_spec.rb')
| -rw-r--r-- | spec/controllers/api/v1/tutorials_controller_spec.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/tutorials_controller_spec.rb b/spec/controllers/api/v1/tutorials_controller_spec.rb new file mode 100644 index 00000000..e4845072 --- /dev/null +++ b/spec/controllers/api/v1/tutorials_controller_spec.rb @@ -0,0 +1,38 @@ +require "rails_helper" + +describe Api::V1::TutorialsController do + let(:user) { create(:user) } + + before :each do + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials(user.authentication_token) + end + + describe "#index" do + let(:my_tutorial) { create(:tutorial, user: user) } + let(:other_tutorial) { create(:tutorial) } + + + it "returns the users tutorials" do + get :index, format: :json + expect(assigns(:tutorials)).to include(my_tutorial) + expect(assigns(:tutorials)).to_not include(other_tutorial) + end + end + + describe "#create" do + it "creates a new tutorial" do + attributes = { + url: "https://twitter.com/", + image_url: "https://abs.twimg.com/a/1405611403/img/t1/front_page/exp_wc2014_gen_laurenlemon.jpg", + heading: "Twitter", + description: "Connect with your friends - and other fascinating people. Get in-the-moment updates on the things that interest you. And watch events unfold, in real time, from every angle.", + } + post :create, tutorial: attributes, format: :json + + expect(assigns(:tutorial)).to be_present + expect(assigns(:tutorial).url).to eql(attributes[:url]) + expect(assigns(:tutorial).description).to eql(attributes[:description]) + expect(assigns(:tutorial).heading).to eql(attributes[:heading]) + end + end +end |
