require "rails_helper" #-#-#-#-#REST#-#-#-#-# RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Index" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end # get /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %> it "Gets all of the <%= HorsePower.get_singular(resource_name) %>s" do FactoryGirl.create_list(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>, 10) get 'api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>', nil, @header expect(response.status).to eq(200) #ok expect(<%= HorsePower.get_camel(resource_name) %>.count).to eq(10) expect(json["<%= HorsePower.get_plural(resource_name) %>"].length).to eq(10) end end end RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Show" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end # get /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/1 it "Gets a <%= HorsePower.get_singular(resource_name) %> by id" do <%= HorsePower.get_singular(resource_name) %> = FactoryGirl.create(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>) get "api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/#{<%= HorsePower.get_singular(resource_name) %>.id}", nil, @header expect(response.status).to eq(200) #ok end end end RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Create" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end # post /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %> it "Creates <%= HorsePower.get_singular(resource_name) %>" do attrs = FactoryGirl.attributes_for(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>) #attrs[:column] = "DefaultString" hash = {"<%= HorsePower.get_singular(resource_name) %>" => attrs} post 'api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>', hash, @header expect(response.status).to eq(200) #ok end end end RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Update" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end # patch/put /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/1 it "Updates <%= HorsePower.get_singular(resource_name) %>" do #Create the <%= HorsePower.get_singular(resource_name) %> through the api attrs = FactoryGirl.attributes_for(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>) #attrs[:column] = "DefaultString" <%= HorsePower.get_singular(resource_name) %> = FactoryGirl.create(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>) hash = {"<%= HorsePower.get_singular(resource_name) %>" => attrs} put "api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/#{<%= HorsePower.get_singular(resource_name) %>.id}", hash, @header expect(response.status).to eq(200) #ok end end end RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Destroy" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end # delete /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/1 it "Deletes <%= HorsePower.get_singular(resource_name) %>" do #Create the <%= HorsePower.get_singular(resource_name) %> through the api attrs = FactoryGirl.attributes_for(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>) #attrs[:column] = "DefaultString" <%= HorsePower.get_singular(resource_name) %> = FactoryGirl.create(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>) expect(<%= HorsePower.get_camel(resource_name) %>.count).to eq(1) #Now delete the <%= HorsePower.get_singular(resource_name) %> through the api delete "api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/#{<%= HorsePower.get_singular(resource_name) %>.id}", nil, @header expect(json).to eq({}) expect(response.status).to eq(200) #ok expect(<%= HorsePower.get_camel(resource_name) %>.count).to eq(0) end end end #-#-#-#-#Collection Routes#-#-#-#-# RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Collection Routes" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end # get /api/1/collection it "checks response of a collection route" do end end end #-#-#-#-#Serialization#-#-#-#-# RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Serialization" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end it "checks the index json sent back" do end end end #-#-#-#-#Errors#-#-#-#-# RSpec.describe <%= HorsePower.get_camel(resource_name) %>, :type => :request do describe "Errors" do before(:example) do @user = FactoryGirl.create(:user_<%= api_version %>) token = @user.tokens[0].auth_token @header = {::Settings.token_header => token, "Email" => @user.email, ::Settings.main_api_header => ::Settings.main_api_key} end # get /api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/1 it "checks for a 404" do <%= HorsePower.get_singular(resource_name) %> = FactoryGirl.create(:<%= HorsePower.get_singular(resource_name) %>_<%= api_version %>) get "api/<%= api_version %>/<%= HorsePower.get_plural(resource_name) %>/#{<%= HorsePower.get_singular(resource_name) %>.id + 1}", nil, @header expect(response.status).to eq(404) #ok end end end