diff options
| author | mo khan <mo@mokhan.ca> | 2014-07-20 08:48:35 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-07-20 08:48:35 -0600 |
| commit | a4aac3783c9e0bb496de50fc288f4b85b82aab39 (patch) | |
| tree | 69dfcc73de64d09dd471f1c9281557d63728a831 /spec/controllers/api | |
| parent | 969cae58d4fbc2f74595d06879e53bcd4ce9d120 (diff) | |
add create action to tutorials controller.
Diffstat (limited to 'spec/controllers/api')
| -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 |
