diff --git a/Gemfile b/Gemfile index 8d870eb..c40c54f 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,6 @@ source 'https://rubygems.org' # Declare your gem's dependencies in rp.gemspec. # Bundler will treat runtime dependencies like base dependencies, and # development dependencies will be added by default to the :development group. -gem 'will_paginate' gemspec # Declare any dependencies that are still in development here instead of in diff --git a/spec/controllers/rp/authorized_user_controller_spec.rb b/spec/controllers/rp/authorized_user_controller_spec.rb index 2a3c6db..36d8dd7 100644 --- a/spec/controllers/rp/authorized_user_controller_spec.rb +++ b/spec/controllers/rp/authorized_user_controller_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' module Rp - RSpec.describe AuthorizedUserController, type: :controller do + RSpec.describe Rp::AuthorizedUsersController, type: :controller do end end diff --git a/spec/controllers/rp/reports_controller_spec.rb b/spec/controllers/rp/reports_controller_spec.rb index 661dcdc..2533f5d 100644 --- a/spec/controllers/rp/reports_controller_spec.rb +++ b/spec/controllers/rp/reports_controller_spec.rb @@ -8,7 +8,7 @@ module Rp # @request.env["devise.mapping"] = Devise.mappings[:user] # sign_in user # allow(controller).to receive(:current_user).and_return(user) - Rp.broker_uuid = 'ABC-123-12' + user = FactoryGirl.create(:user) end describe "GET #index" do @@ -21,16 +21,6 @@ module Rp end end - describe "GET #new" do - - let(:report) { FactoryGirl.create(:rp_report) } - - it "assigns a new report as @report" do - get :new - expect(assigns(:report)).to be_a_new(Report) - end - end - describe "POST #create" do let(:available_report) { FactoryGirl.create(:rp_available_report) } diff --git a/spec/controllers/rp/settings_controller_spec.rb b/spec/controllers/rp/settings_controller_spec.rb index 2e055d4..c47701d 100644 --- a/spec/controllers/rp/settings_controller_spec.rb +++ b/spec/controllers/rp/settings_controller_spec.rb @@ -21,141 +21,5 @@ module Rp RSpec.describe SettingsController, type: :controller do - # This should return the minimal set of attributes required to create a valid - # Setting. As you add validations to Setting, be sure to - # adjust the attributes here as well. - let(:valid_attributes) { - skip("Add a hash of attributes valid for your model") - } - - let(:invalid_attributes) { - skip("Add a hash of attributes invalid for your model") - } - - # This should return the minimal set of values that should be in the session - # in order to pass any filters (e.g. authentication) defined in - # SettingsController. Be sure to keep this updated too. - let(:valid_session) { {} } - - describe "GET #index" do - it "assigns all settings as @settings" do - setting = Setting.create! valid_attributes - get :index, params: {}, session: valid_session - expect(assigns(:settings)).to eq([setting]) - end - end - - describe "GET #show" do - it "assigns the requested setting as @setting" do - setting = Setting.create! valid_attributes - get :show, params: {id: setting.to_param}, session: valid_session - expect(assigns(:setting)).to eq(setting) - end - end - - describe "GET #new" do - it "assigns a new setting as @setting" do - get :new, params: {}, session: valid_session - expect(assigns(:setting)).to be_a_new(Setting) - end - end - - describe "GET #edit" do - it "assigns the requested setting as @setting" do - setting = Setting.create! valid_attributes - get :edit, params: {id: setting.to_param}, session: valid_session - expect(assigns(:setting)).to eq(setting) - end - end - - describe "POST #create" do - context "with valid params" do - it "creates a new Setting" do - expect { - post :create, params: {setting: valid_attributes}, session: valid_session - }.to change(Setting, :count).by(1) - end - - it "assigns a newly created setting as @setting" do - post :create, params: {setting: valid_attributes}, session: valid_session - expect(assigns(:setting)).to be_a(Setting) - expect(assigns(:setting)).to be_persisted - end - - it "redirects to the created setting" do - post :create, params: {setting: valid_attributes}, session: valid_session - expect(response).to redirect_to(Setting.last) - end - end - - context "with invalid params" do - it "assigns a newly created but unsaved setting as @setting" do - post :create, params: {setting: invalid_attributes}, session: valid_session - expect(assigns(:setting)).to be_a_new(Setting) - end - - it "re-renders the 'new' template" do - post :create, params: {setting: invalid_attributes}, session: valid_session - expect(response).to render_template("new") - end - end - end - - describe "PUT #update" do - context "with valid params" do - let(:new_attributes) { - skip("Add a hash of attributes valid for your model") - } - - it "updates the requested setting" do - setting = Setting.create! valid_attributes - put :update, params: {id: setting.to_param, setting: new_attributes}, session: valid_session - setting.reload - skip("Add assertions for updated state") - end - - it "assigns the requested setting as @setting" do - setting = Setting.create! valid_attributes - put :update, params: {id: setting.to_param, setting: valid_attributes}, session: valid_session - expect(assigns(:setting)).to eq(setting) - end - - it "redirects to the setting" do - setting = Setting.create! valid_attributes - put :update, params: {id: setting.to_param, setting: valid_attributes}, session: valid_session - expect(response).to redirect_to(setting) - end - end - - context "with invalid params" do - it "assigns the setting as @setting" do - setting = Setting.create! valid_attributes - put :update, params: {id: setting.to_param, setting: invalid_attributes}, session: valid_session - expect(assigns(:setting)).to eq(setting) - end - - it "re-renders the 'edit' template" do - setting = Setting.create! valid_attributes - put :update, params: {id: setting.to_param, setting: invalid_attributes}, session: valid_session - expect(response).to render_template("edit") - end - end - end - - describe "DELETE #destroy" do - it "destroys the requested setting" do - setting = Setting.create! valid_attributes - expect { - delete :destroy, params: {id: setting.to_param}, session: valid_session - }.to change(Setting, :count).by(-1) - end - - it "redirects to the settings list" do - setting = Setting.create! valid_attributes - delete :destroy, params: {id: setting.to_param}, session: valid_session - expect(response).to redirect_to(settings_url) - end - end - end end diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb index d83690e..bafb3da 100644 --- a/spec/dummy/app/controllers/application_controller.rb +++ b/spec/dummy/app/controllers/application_controller.rb @@ -2,4 +2,16 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + private + + def authenticate_user! + end + + def block_inactive_user! + end + + def current_user + User.first + end end diff --git a/spec/dummy/app/models/user.rb b/spec/dummy/app/models/user.rb new file mode 100644 index 0000000..7b1f39c --- /dev/null +++ b/spec/dummy/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ActiveRecord::Base + + def has_role?(role) + true + end +end \ No newline at end of file diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 3283fc1..f0b64f9 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -10,6 +10,8 @@ Bundler.require(*Rails.groups) require "rp" +require "haml-rails" +require "will_paginate" module Dummy class Application < Rails::Application diff --git a/spec/dummy/db/migrate/20170501065922_create_users.rb b/spec/dummy/db/migrate/20170501065922_create_users.rb new file mode 100644 index 0000000..f6ba67d --- /dev/null +++ b/spec/dummy/db/migrate/20170501065922_create_users.rb @@ -0,0 +1,7 @@ +class CreateUsers < ActiveRecord::Migration + def change + create_table :users do |t| + t.string :name + end + end +end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index d22a28a..e13ffe9 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161223143345) do +ActiveRecord::Schema.define(version: 20170501065922) do create_table "rp_authorized_users", force: :cascade do |t| t.integer "available_report_id" @@ -21,50 +21,64 @@ add_index "rp_authorized_users", ["available_report_id", "user_id"], name: "index_rp_authorized_users_on_available_report_id_and_user_id", unique: true create_table "rp_available_reports", force: :cascade do |t| - t.string "name", null: false - t.string "dsn" - t.string "db_unit" - t.string "batch_size" + t.string "name", null: false + t.string "dsn", null: false + t.string "db_unit", null: false t.string "msg_model" t.string "mime_type" t.string "file_ext" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "params_cnt" - t.string "param1", limit: 500 - t.string "param2", limit: 500 - t.string "param3", limit: 500 - t.string "param4", limit: 500 - t.string "param5", limit: 500 - t.string "is_public", default: "Y" + t.string "param1", limit: 500 + t.string "param2", limit: 500 + t.string "param3", limit: 500 + t.string "param4", limit: 500 + t.string "param5", limit: 500 + t.string "is_public", default: "Y" + t.integer "batch_size", default: 50, null: false + t.string "header_kind", limit: 1, default: "C", null: false + t.string "money_format", limit: 20, default: "###,###,##0.00", null: false + t.string "normalize_space", limit: 1, default: "Y" + t.string "delimiter", limit: 1, default: "," + t.string "escape_character", limit: 1, default: "\"" + t.string "service_code", limit: 100, default: "RP" end create_table "rp_pending_reports", force: :cascade do |t| - t.string "broker_uuid", limit: 500 + t.string "broker_uuid", limit: 500 t.datetime "created_at" t.integer "report_id" t.datetime "run_at" + t.string "service_code", limit: 100 end + add_index "rp_pending_reports", ["broker_uuid"], name: "index_rp_pending_reports_on_broker_uuid" + add_index "rp_pending_reports", ["report_id"], name: "index_rp_pending_reports_on_report_id", unique: true + create_table "rp_reports", force: :cascade do |t| - t.string "name", null: false - t.string "state", null: false - t.datetime "queued_at", null: false + t.string "name", limit: 100, null: false + t.string "state", limit: 50, null: false + t.datetime "queued_at", null: false t.string "mime_type" - t.string "created_by", null: false + t.string "created_by", limit: 20 t.string "report_url" t.string "notify_to" + t.string "dsn" + t.string "db_unit" + t.string "batch_size" + t.string "msg_model" + t.string "file_ext" t.datetime "started_at" t.datetime "finished_at" t.integer "line_count" t.integer "size_in_bytes" t.string "file_name" t.string "file_path" - t.string "fault_code" - t.string "fault_subcode" - t.string "fault_reason" + t.string "fault_code", limit: 50 + t.string "fault_subcode", limit: 50 + t.string "fault_reason", limit: 1000 t.text "fault_bitstream" - t.integer "rp_available_reports_id" t.string "param1" t.string "param2" t.string "param3" @@ -72,24 +86,26 @@ t.string "param5" t.string "file_url" t.string "email_alert_ref_no" + t.string "broker_uuid", limit: 100 + t.string "header_kind", limit: 1, default: "C", null: false + t.string "money_format", limit: 20, default: "###,###,##0.00", null: false + t.string "normalize_space", limit: 1, default: "Y" + t.string "delimiter", limit: 1, default: "," + t.string "escape_character", limit: 1, default: "\"" + t.string "service_code", limit: 100 end + add_index "rp_reports", ["state", "broker_uuid"], name: "index_rp_reports_on_state_and_broker_uuid" + create_table "rp_settings", force: :cascade do |t| - t.string "scheme" + t.string "scheme", null: false t.string "host" t.string "username" t.string "password" t.string "virtual_path" - t.integer "max_age_days" - t.integer "max_per_user" - end - - create_table "rp_setups", force: :cascade do |t| - t.string "scheme" - t.string "host" - t.string "username" - t.string "password" - t.string "virtual_path" + t.integer "max_age_days", default: 7, null: false + t.integer "max_per_user", default: 7, null: false + t.integer "query_timeout", default: 60 end create_table "rp_users", force: :cascade do |t| @@ -111,4 +127,8 @@ add_index "rp_users", ["email"], name: "index_rp_users_on_email", unique: true add_index "rp_users", ["reset_password_token"], name: "index_rp_users_on_reset_password_token", unique: true + create_table "users", force: :cascade do |t| + t.string "name" + end + end diff --git a/spec/factories/rp_available_reports.rb b/spec/factories/rp_available_reports.rb index 414ce33..f1d270b 100644 --- a/spec/factories/rp_available_reports.rb +++ b/spec/factories/rp_available_reports.rb @@ -1,5 +1,11 @@ FactoryGirl.define do factory :rp_available_report, class: 'Rp::AvailableReport' do - name 'ABC Report' + name 'FT2 Report' + dsn 'SC' + db_unit 'pk_qg_test_package.get_neft_report' + batch_size 50 + msg_model 'FT2-Model' + mime_type 'text/plain' + header_kind 'C' end end diff --git a/spec/factories/rp_reports.rb b/spec/factories/rp_reports.rb index ff1278d..b372a0d 100644 --- a/spec/factories/rp_reports.rb +++ b/spec/factories/rp_reports.rb @@ -4,6 +4,7 @@ state 'new' queued_at '2015-12-12' mime_type 'csv' - created_by 'divya' + created_by 1 + available_report_id { FactoryGirl.create(:rp_available_report).id } end end diff --git a/spec/factories/rp_settings.rb b/spec/factories/rp_settings.rb index c81f32d..d18c503 100644 --- a/spec/factories/rp_settings.rb +++ b/spec/factories/rp_settings.rb @@ -1,5 +1,4 @@ FactoryGirl.define do factory :rp_setting, class: 'Rp::Setting' do - end end diff --git a/spec/factories/rp_users.rb b/spec/factories/rp_users.rb deleted file mode 100644 index 3e1ede1..0000000 --- a/spec/factories/rp_users.rb +++ /dev/null @@ -1,7 +0,0 @@ -FactoryGirl.define do - factory :rp_user, class: 'Rp::User' do - name 'divya' - email 'divya@abc.com' - password 'password' - end -end diff --git a/spec/factories/users.rb b/spec/factories/users.rb new file mode 100644 index 0000000..1b320f5 --- /dev/null +++ b/spec/factories/users.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :user, class: 'User' do + name 'divya' + end +end diff --git a/spec/models/rp/pending_report_spec.rb b/spec/models/rp/pending_report_spec.rb index 8ca2c28..5958f6a 100644 --- a/spec/models/rp/pending_report_spec.rb +++ b/spec/models/rp/pending_report_spec.rb @@ -5,19 +5,5 @@ module Rp context 'association' do it { should belong_to(:report) } end - - context 'validate' do - it 'should be not valid when broker_uuid is not set' do - Rp.broker_uuid = nil - pending_report = FactoryGirl.build(:rp_pending_report) - expect(pending_report.valid?).to eq(false) - end - - it 'should be valid when broker_uuid is set' do - Rp.broker_uuid = 'ABC-123-12' - pending_report = FactoryGirl.build(:rp_pending_report) - expect(pending_report.valid?).to eq(true) - end - end end end diff --git a/spec/models/rp/report_spec.rb b/spec/models/rp/report_spec.rb index 4003250..6bd3810 100644 --- a/spec/models/rp/report_spec.rb +++ b/spec/models/rp/report_spec.rb @@ -4,12 +4,10 @@ module Rp RSpec.describe Report, type: :model do context 'association' do it { should have_one(:pending_report) } - it { should accept_nested_attributes_for(:pending_report) } end - context 'enqueue_report' do - it 'should enqueue report when broker_uuid is set' do - Rp.broker_uuid = 'ABC-123-12' + context 'create_pending_report' do + it 'should enqueue report' do report = FactoryGirl.build(:rp_report) expect(report.save).to eq(true) expect(report.pending_report).not_to be_nil