diff --git a/Gemfile b/Gemfile index e37ced927b..b4d9353613 100644 --- a/Gemfile +++ b/Gemfile @@ -195,3 +195,5 @@ gem "pagy", "> 8" gem "csv" gem "avo-meta", github: "avo-hq/avo-meta", branch: "main" + +gem "store_model" diff --git a/Gemfile.lock b/Gemfile.lock index 5715c0b150..216f293875 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/avo-hq/avo-meta.git - revision: 874345836c3e686c2d716a0ae542caaad3aa8cab + revision: 9411e7a21a3f15b4c3e8a77c1b8df15f879be93d branch: main specs: avo-meta (0.1.0) @@ -762,6 +762,7 @@ DEPENDENCIES spring-commands-rspec sprockets-rails standard + store_model test-prof tzinfo-data web-console (>= 3.3.0) diff --git a/db/factories.rb b/db/factories.rb index a9541adbd6..0fb8983935 100644 --- a/db/factories.rb +++ b/db/factories.rb @@ -37,7 +37,7 @@ factory :project do name { Faker::App.name } - status { ['closed', :rejected, :failed, 'loading', :running, :waiting].sample } + status { ["closed", :rejected, :failed, "loading", :running, :waiting].sample } stage { ["Discovery", "Idea", "Done", "On hold", "Cancelled", "Drafting"].sample } budget { Faker::Number.decimal(l_digits: 4) } country { Faker::Address.country_code } @@ -148,4 +148,13 @@ name { Faker::Company.name } size { ["small", "medium", "large"].sample } end + + factory :meta_schema, class: "Avo::Meta::Schema" do + resource_name { "User" } + schema_entries { + [ + Avo::Meta::SchemaEntry.new(name: "shoe_size", type: "integer", as: "number") + ] + } + end end diff --git a/spec/system/avo/meta/user_meta_spec.rb b/spec/system/avo/meta/user_meta_spec.rb new file mode 100644 index 0000000000..0808fb339a --- /dev/null +++ b/spec/system/avo/meta/user_meta_spec.rb @@ -0,0 +1,46 @@ +require "rails_helper" + +RSpec.describe "UserMeta", type: :system do + let!(:user) { create :user } + let!(:schema) { create :meta_schema } + + it "allows to add new entries to the user meta schema" do + visit "/admin/resources/meta_schemas" + + click_on "User" + end + + it "allows to add new entries to the user meta schema, which can instantly be used" do + visit "/admin/resources/meta_schemas" + + within "#avo_meta_schemas_list" do + find("td", text: "User").click + end + + click_on "Edit" + + click_on "Add a new property" + + fill_in "Name", with: "nickname" + select "string", from: find('select[name*="[schema_entries_attributes]["][name*="][type]"]')[:id] + select "text", from: find('select[name*="[schema_entries_attributes]["][name*="][as]"]')[:id] + + save + + expect(page).to have_text("Meta schema was successfully updated") + + # assert that the new attribute is actually present and editable + visit avo.resources_user_path(User.last) + + expect(page).to have_text("Meta") + expect(page).to have_text("NICKNAME") + + click_on "Edit" + + fill_in "user_meta_nickname", with: "Ace Ventura" + + save + + expect(page).to have_text("Ace Ventura") + end +end