Skip to content

Commit

Permalink
docs: update docs for preparation and adding reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
namiwang committed Apr 30, 2022
1 parent 69dea2a commit 599bf37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If bundler is not being used to manage dependencies, install the gem by executin

$ gem install acts_as_reactable

## Usage
## Preparations

### 1. create the Reaction model

Expand Down Expand Up @@ -54,13 +54,16 @@ class User < ApplicationRecord
end
```

### 3. creating/updating reactions
## Usage

### adding/updating reactions

```ruby
reaction = post.update_reaction_from(user, "πŸ˜€")
post.add_reactions(user, "πŸ˜€")
post.add_reactions(user, ["😞", "πŸ™ƒ"])
```

### 4. deleting reactions
### deleting reactions

```ruby
post.destroy_reaction_from(user) # returns value like #destroy in ActiveRecord
Expand All @@ -69,13 +72,13 @@ post.destroy_reaction_from(user) # returns value like #destroy in ActiveRecord
post.update_reaction_from(user)
```

### 5. private opinion from one reactor
### private opinion from one reactor

```ruby
reaction = ActsAsReactable::Reaction.find_by(reactable: self, reactor: user)&.emoji
```

### 6. group, count and sort to get a summary of public opinion
### group, count and sort to get a summary of public opinion

```ruby
ActsAsReactable::Reaction.where(reactable: reactor).group(:emoji).order('count_id DESC').count(:id)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/acts_as_reactable/reactable/add_reactions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
it "ignores invalid emoji" do
expect {
post.add_reactions(user, %w[πŸ”΄ 🟑 "A"])
# NOTE using id not being nil to check if the reaction was created
# NOTE using id not being nil to filter invalid reactions
expect(post.reactions.where.not(id: nil).map(&:emoji)).to eq(%w[πŸ”΄ 🟑])
}.to change(ActsAsReactable::Reaction, :count).by(2)
end
Expand Down

0 comments on commit 599bf37

Please sign in to comment.