Sha256: 7592d79258267ed61960e8aff46e9b2e5225fdcf5e9f76949bb8a1f0d9cbd02c
Contents?: true
Size: 1.66 KB
Versions: 6
Compression:
Stored size: 1.66 KB
Contents
module Souls module Generate class << self ## Generate Rspec Policy def rspec_policy class_name: "souls" dir_name = "./spec/policies" FileUtils.mkdir_p dir_name unless Dir.exist? dir_name file_path = "./spec/policies/#{class_name}_policy_spec.rb" return "RspecPolicy already exist! #{file_path}" if File.exist? file_path File.open(file_path, "w") do |new_line| new_line.write <<~EOS describe #{class_name.camelize}Policy do subject { described_class.new(user, #{class_name.underscore}) } let(:#{class_name.underscore}) { FactoryBot.create(:#{class_name.underscore}) } context "being a visitor" do let(:user) { FactoryBot.create(:user, user_role: :normal) } it { is_expected.to permit_action(:index) } it { is_expected.to permit_action(:show) } it { is_expected.to forbid_actions([:create, :update, :delete]) } end context "being a user" do let(:user) { FactoryBot.create(:user, user_role: :user) } it { is_expected.to permit_actions([:create, :update]) } end context "being an admin" do let(:user) { FactoryBot.create(:user, user_role: :admin) } it { is_expected.to permit_actions([:create, :update, :delete]) } end end EOS end puts Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }] file_path rescue StandardError => e raise StandardError, e end end end end
Version data entries
6 entries across 6 versions & 1 rubygems